Handle errors with the SQLException class

Whenever an error occurs from either Informix® JDBC Driver or the database server, an SQLException is raised. Use the following methods of the SQLException class to retrieve the text of the error message, the error code, and the SQLSTATE value:
getMessage()
Returns a description of the error

SQLException inherits this method from the java.util.Throwable class.

getErrorCode()
Returns an integer value that corresponds to the Informix database server or Informix JDBC Driver error code
getSQLState()
Returns a string that describes the SQLSTATE value

The string follows the X/Open SQLSTATE conventions.

All Informix JDBC Driver errors have error codes of the form -79XXX, such as -79708: Can't take null input.

For a list of Informix database server errors, see Informix Error Messages. For a list of Informix JDBC Driver errors, see Error messages.

The following example from the SimpleSelect.java program shows how to use the SQLException class to catch Informix JDBC Driver or database server errors by using a try-catch block:
try
   {
   PreparedStatement pstmt = conn.prepareStatement("Select * 
      from x "
      + "where a = ?;");
   pstmt.setInt(1, 11);
   ResultSet r = pstmt.executeQuery();
   while(r.next())
      {
      short i = r.getShort(1);
      System.out.println("Select: column a = " + i);
      }
   r.close();
   pstmt.close();
   }
catch (SQLException e)
   {
   System.out.println("ERROR: Fetch statement failed: " +
      e.getMessage());
   }