public static int getGeneratedKey ( PreparedStatement statement ) throws DatabaseException { ResultSet rs = null ; int id = 0 ; try { rs = statement . getGeneratedKeys ( ) ; if ( ! rs . next ( ) ) { throw new DatabaseException ( "Unable to get primary key for inserted row" ) ; } id = rs . getInt ( 1 ) ; } catch ( SQLException ex ) { throw new DatabaseException ( "Unable to get primary key for inserted row" ) ; } finally { closeResultSet ( rs ) ; } return id ; }
Returns the generated integer primary key for a newly inserted row .