returning autogenerated primary key after insertion
HiI am inserting a row into the database using simple jdbc statement. The primary key for that row is autogenerated by the database.Is there any way to get the primary key and return it to the user?
# 1
PreparedStatement ps = con.preparedStatement("INSERT INTO Table (title, name) VALUES ("test", "name")", PreparedStatement.RETURN_GENERATED_KEYS);ps.executrUpdate();ResultSet rs = ps.getGeneratedKeys();while (rs.next()) {primaryKey = rs.getInt(1);}