public static int firstIntKey ( PreparedStatement stmt ) throws SQLException { stmt . execute ( ) ; ResultSet rs = stmt . getGeneratedKeys ( ) ; int key = rs . next ( ) ? rs . getInt ( 1 ) : 0 ; stmt . close ( ) ; return key ; }
Execute the insert statement get the first generated key as an int and close the statement .