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();
}
} |