Handle errors with the SQLException class

Whenever an error occurs from either HCL OneDB™ 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 HCL OneDB database server or HCL OneDB JDBC Driver error code
getSQLState()
Returns a string that describes the SQLSTATE value

The string follows the X/Open SQLSTATE conventions.

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

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

The following example from the SimpleSelect.java program shows how to use the SQLException class to catch HCL OneDB 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());
   }