Whenever an error occurs from either IBM 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:
Returns a description of the error
SQLException inherits this method from the java.util.Throwable class.
Returns an integer value that corresponds to the Informix database server or IBM Informix JDBC Driver error code
Returns a string that describes the SQLSTATE value
The string follows the X/Open SQLSTATE conventions.
All IBM Informix JDBC Driver errors have error codes of the form -79XXX, such as -79708 Method can't take null parameter.
For a list of Informix database server errors, refer to IBM Informix: Error Messages. You can find the online version of this guide at http://www.ibm.com/software/data/informix/pubs/library/. For a list of IBM Informix JDBC Driver errors, see Error Messages near the end of this book.
The following example from the SimpleSelect.java program shows how to use the SQLException class to catch IBM Informix JDBC Driver or database server errors 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()); }Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]