I created a 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:
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 = connection.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();
}
}