The Artima Developer Community
Sponsored Link

Java Answers Forum
Database connection

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
joe douglas

Posts: 3
Nickname: oaklander
Registered: Aug, 2007

Database connection Posted: Nov 12, 2007 8:55 AM
Reply to this message Reply
Advertisement
My JSP is working great with a Java class that inserts and updates an Oracle 9i database. I am running single insert and single update statements in my program that is used about 10 times a week at most.
The below is what I have been using and was wondering if it is efficient or anyway to improve it:


public class DbWork
{

private Connection connection = new ConnectionMgr().getConnection();
private PreparedStatement stat;

public void cityInserter(FormBean city) throws SQLException {
stat = connection.prepareStatement("Insert into City (street, school) values (?,?)");
stat.setString(1, city.getStreet());
stat.setString(2, city.getSchool());
stat.executeUpdate();
}

public void cityUpdater(FormBean city) throws SQLException {
//update another table in the database using preparedstatements
}
.......

public void dbMethod(FormBean city)
{
try
{
cityInserter(city);
cityUpdater(city);
}
catch(SQLException ex)
{
System.out.println(ex);
}
finally
{
connection.close();
}

.....
}

Topic: Database connection Previous Topic   Next Topic Topic: palindrome numbers with threads in java

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use