Handling numeric errors returned as warnings

In Adaptive Server 12.0 through 12.5, numeric errors are handled, by default, as severity 10. A severity-level 10 message is classified as a status information message, not as an error, and its content is transferred to a SQLWarning object. This code illustrates this processing:

static void processWarnings(SQLWarning warning) { 
   if (warning != null) { 
      System.out.println ("\n -- Warning received -- \n"); 
   }
   while (warning != null) { 
      System.out.println ("Message: " + warning.getMessage()); 
      System.out.println ("SQLState: " + warning.getSQLState()); 
      System.out.println ("ErrorCode: " + warning.getErrorCode()); 
      System.out.println ("------------------------------------"); 
      warning = warning.getNextWarning(); 
   }
}

When a numeric error occurs, the returned ResultSet object does not contain result set data, and you must retrieve the error information from SQLWarning. Therefore, in a JDBC application, the code that checks for and processes a SQLWarning should not expect a result set. For example, this code checks for and processes SQLWarning data both inside and outside the result set processing while loop:

while (rs.next()) { 
   String value = rs.getString(1); 
   System.out.println ("Fetched value: " + value); 

   // Check for SQLWarning on the result set.
   processWarnings (rs.getWarnings()); 

}

// Check for SQLWarning on the result set.
processWarnings (rs.getWarnings());

The preceding code checks for SQLWarning even if there is no result set data (rs.next( ) is false).

This is an output of a program that detected an error caused by dividing a number by zero:

-- Warning received -- 

Message: Divide by zero occurred.
SQLState: 01012 
ErrorCode: 3607