Informix JDBC Driver Programmer's Guide
Chapter 2: Programming with Informix JDBC Driver
Contents
Index
Handling Errors
Use the
JDBC
API
SQLE
xception
class to handle errors in your Java program. The Informix-specific
com.informix.jdbc.Message
class can also be used outside a Java program to retrieve the Informix error text for a given error number.
Using the SQLException Class
Whenever an error occurs from either Informix JDBC Driver or the database server, an
SQLE
xception
is raised. Use the following methods of the
SQLE
xception
class to retrieve the text of the error message, the error code, and the
SQLS
tate:
getMessage()
Returns a description of the error.
SQLE
xception
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
SQLS
tate. The string follows the
X/O
pen
SQLS
tate conventions.
All 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
Informix Error Messages
. You can find the on-line version of this guide at the following Web site:
http://www.informix.com/answers
.
The following example from the
SimpleSelect.java
program shows how to use the
SQLE
xception
class to catch 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());
}
Retrieving Informix Error Message Text
Informix provides the class
com.informix.jdbc.Message
for retrieving the Informix error message text based on the Informix error number. To use this class, call the Java interpreter
java
directly, passing it an Informix error number, as shown in the following example:
java com.informix.jdbc.Message 100
The example returns the message text for Informix error 100:
100: ISAM error: duplicate value for a record with unique key.
Informix JDBC Driver Programmer's Guide
, Version 1.22
Copyright © 1998, Informix Software, Inc. All rights reserved.