Thursday, July 22, 2010

Getting Current Inserted Record's Primary Key

PreparedStatement pstmt = conn.prepareStatement(SQL_QUERY);

pstmt.executeUpdate();

ResultSet rs = pstmt.getGeneratedKeys();
int key = -1;
if (rs.next()) {
    key = rs.getInt(1);
}

here key will return the current inserted record's primary key.

No comments:

Post a Comment