static public int obtainNextIncrementInteger ( Connection connection , ColumnData autoIncrementIntegerColumn ) throws Exception { try { String sqlQuery = "SELECT nextval(?);" ; // Create SQL command PreparedStatement pstmt = null ; { pstmt = connection . prepareStatement ( sqlQuery ) ; // Populate prepared statement pstmt . setString ( 1 , autoIncrementIntegerColumn . getAutoIncrementSequence ( ) ) ; } if ( pstmt . execute ( ) ) { ResultSet rs = pstmt . getResultSet ( ) ; if ( rs . next ( ) ) { int nextValue = rs . getInt ( 1 ) ; return nextValue ; } else { throw new Exception ( "Empty result returned by SQL: " + sqlQuery ) ; } } else { throw new Exception ( "No result returned by SQL: " + sqlQuery ) ; } } catch ( Exception e ) { throw new Exception ( "Error while attempting to get a auto increment integer value for: " + autoIncrementIntegerColumn . getColumnName ( ) + " (" + autoIncrementIntegerColumn . getAutoIncrementSequence ( ) + ")" , e ) ; } }
Performs a database query to find the next integer in the sequence reserved for the given column .