code_junkie

Primary key from inserted row jdbc?

Nov 11th, 2011
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. pInsertOid = connection.prepareStatement(INSERT_OID_SQL, Statement.RETURN_GENERATED_KEYS);
  2.  
  3. // fill in the prepared statement and
  4. pInsertOid.executeUpdate();
  5. ResultSet rs = pInsertOid.getGeneratedKeys();
  6. if (rs.next()) {
  7. int newId = rs.getInt(1);
  8. oid.setId(newId);
  9. }
Add Comment
Please, Sign In to add comment