View Single Post
  #1 (permalink)  
Old 11-12-2007, 10:46 PM
oaklander oaklander is offline
Member
 
Join Date: Nov 2007
Posts: 2
oaklander is on a distinguished road
Database connection
I created my first Java class that inserts and updates an Oracle 9i database. I am running single insert and single update statements.
The below is what I have been using and was wondering if it is efficient or anyway to improve it:

Code:
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 { stat = con.prepareStatement("update Person set PersonId = ? where name LIKE ? "); stat.setInt(1, city.getPersonId()); stat.setString(2, city.getName()); stat.executeUpdate(): } public void dbMethod(FormBean city) { try { cityInserter(city); cityUpdater(city); } catch(SQLException ex) { System.out.println(ex); } finally { connection.close(); } }
Reply With Quote
Sponsored Links