public void create(Address address) throws SQLException { Connection connection = ds.getConnection(); try { Statement statement = connection.createStatement(); try { statement.executeUpdate( "insert into address (street, city, state, zip) values ('" + address.getStreet() + "', '" + address.getCity() + "', '" + address.getState() + "', '" + address.getZip() + "')", Statement.RETURN_GENERATED_KEYS); ResultSet generatedKeys = statement.getGeneratedKeys(); try { if (generatedKeys.next()) { address.setId(generatedKeys.getLong("id")); } } finally { generatedKeys.close(); } } finally { statement.close(); } } finally { connection.close(); } }
public void delete(Address address) throws SQLException { Connection connection = ds.getConnection(); try { Statement statement = connection.createStatement(); try { statement.executeUpdate("delete from address where id=" + address.getId()); } finally { statement.close(); } } finally { connection.close(); } }
public void update(Address address) throws SQLException { Connection connection = ds.getConnection(); try { Statement statement = connection.createStatement(); try { statement.executeUpdate( "update address set street='" + address.getStreet() + "', city='" + address.getCity() + "', state= '" + address.getState() + "', zip='" + address.getZip() + "' where id=" + address.getId()); } finally { statement.close(); } } finally { connection.close(); } }
private static Address unmarshall(ResultSet results) throws SQLException { Address address = new Address(); address.setId(results.getLong("id")); address.setStreet(results.getString("street")); address.setCity(results.getString("city")); address.setState(results.getString("state")); address.setZip(results.getString("zip")); return address; }