code: 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;
      }
docs: Returns the generated integer primary key for a newly inserted row.
  
  @param statement a prepared statement that just executed an insert
  @return a primary key
  @throws DatabaseException thrown if there is an exception obtaining the
  key