question: static SQLWarning convertShowWarningsToSQLWarnings ( Connection connection , int warningCountIfKnown , boolean forTruncationOnly ) throws SQLException { java . sql . Statement stmt = null ; java . sql . ResultSet warnRs = null ; SQLWarning currentWarning = null ; try { if ( warningCountIfKnown < 100 ) { stmt = connection . createStatement ( ) ; if ( stmt . getMaxRows ( ) != 0 ) { stmt . setMaxRows ( 0 ) ; } } else { stmt = connection . createStatement ( java . sql . ResultSet . TYPE_FORWARD_ONLY , java . sql . ResultSet . CONCUR_READ_ONLY ) ; stmt . setFetchSize ( Integer . MIN_VALUE ) ; } warnRs = stmt . executeQuery ( "SHOW WARNINGS" ) ; while ( warnRs . next ( ) ) { int code = warnRs . getInt ( "Code" ) ; if ( forTruncationOnly ) { if ( code == MysqlErrorNumbers . ER_WARN_DATA_TRUNCATED || code == MysqlErrorNumbers . ER_WARN_DATA_OUT_OF_RANGE ) { DataTruncation newTruncation = new MysqlDataTruncation ( warnRs . getString ( "Message" ) , 0 , false , false , 0 , 0 , code ) ; if ( currentWarning == null ) { currentWarning = newTruncation ; } else { currentWarning . setNextWarning ( newTruncation ) ; } } } else { String message = warnRs . getString ( "Message" ) ; SQLWarning newWarning = new SQLWarning ( message , SQLError . mysqlToSqlState ( code , connection . getUseSqlStateCodes ( ) ) , code ) ; if ( currentWarning == null ) { currentWarning = newWarning ; } else { currentWarning . setNextWarning ( newWarning ) ; } } } if ( forTruncationOnly && ( currentWarning != null ) ) { throw currentWarning ; } return currentWarning ; } finally { SQLException reThrow = null ; if ( warnRs != null ) { try { warnRs . close ( ) ; } catch ( SQLException sqlEx ) { reThrow = sqlEx ; } } if ( stmt != null ) { try { stmt . close ( ) ; } catch ( SQLException sqlEx ) { reThrow = sqlEx ; } } if ( reThrow != null ) { throw reThrow ; } } }
target:  Turns output of 'SHOW WARNINGS' into JDBC SQLWarning instances. If 'forTruncationOnly' is true, only looks for truncation warnings, and actually throws DataTruncation as an exception.