@Override public void update(Object obj) throws SQLException { Line line = (Line) obj; String sql = String.format( "UPDATE line SET code='%s', name='%s', type='%s', description='%s' WHERE id = %s;", line.getCode(), line.getName(), line.getType(), line.getDescription(), line.getId()); Statement st = conn.createStatement(); st.executeUpdate(sql); }
@Override public int create(Object obj) throws SQLException { Line line = (Line) obj; String insert = String.format( "INSERT INTO line( code, name, type, description) VALUES ('%s', '%s', '%s', '%s');", line.getCode(), line.getName(), line.getType(), line.getDescription()); Statement st = conn.createStatement(); int id = st.executeUpdate(insert, Statement.RETURN_GENERATED_KEYS); line.setId(id); return id; }