@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; }
@Override public Line read(int id) throws SQLException { Line line = null; String sql = String.format("SELECT * FROM line WHERE line.id = '%s'", id); Statement st; st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = st.executeQuery(sql); rs.first(); line = new Line( rs.getString("code"), rs.getString("name"), rs.getString("type"), rs.getString("description")); line.setId(rs.getInt("id")); return line; }