Handling An Sqlexception Under The Ibm Data Server Driver For Jdbc And Sqlj - IBM DB2 Manual

Table of Contents

Advertisement

SQLException objects are chained in the same order as the corresponding
statements were added to the batch. To help you match SQLException objects to
statements in the batch, the error description field for each SQLException object
begins with this string:
Error for batch element #n:
n is the number of the statement in the batch.
SQL warnings during batch execution do not throw BatchUpdateExceptions. To
obtain information about warnings, use the Statement.getWarnings method on the
object on which you ran the executeBatch method. You can then retrieve an error
description, SQLSTATE, and error code for each SQLWarning object.
SQLWarning
The IBM Data Server Driver for JDBC and SQLJ accumulates warnings when SQL
statements return positive SQLCODEs, and when SQL statements return 0
SQLCODEs with non-zero SQLSTATEs.
Calling getWarnings retrieves an SQLWarning object.
Important: When a call to Statement.executeUpdate or
PreparedStatement.executeUpdate affects no rows, the IBM Data Server Driver for
JDBC and SQLJ generates an SQLWarning with error code +100.
When a call to ResultSet.next returns no rows, the IBM Data Server Driver for
JDBC and SQLJ does not generate an SQLWarning.
A generic SQLWarning object contains the following information:
v A String object that contains a description of the warning, or null
v A String object that contains the SQLSTATE, or null
v An int value that contains an error code
v A pointer to the next SQLWarning, or null
Under the IBM Data Server Driver for JDBC and SQLJ, like an SQLException object,
an SQLWarning object can also contain DB2-specific information. The DB2-specific
information for an SQLWarning object is the same as the DB2-specific information
for an SQLException object.
Handling an SQLException under the IBM Data Server Driver
for JDBC and SQLJ
As in all Java programs, error handling for JDBC applications is done using
try/catch blocks. Methods throw exceptions when an error occurs, and the code in
the catch block handles those exceptions.
The basic steps for handling an SQLException in a JDBC program that runs under
the IBM Data Server Driver for JDBC and SQLJ are:
1. Give the program access to the com.ibm.db2.jcc.DB2Diagnosable interface and
the com.ibm.db2.jcc.DB2Sqlca class. You can fully qualify all references to
them, or you can import them:
import com.ibm.db2.jcc.DB2Diagnosable;
import com.ibm.db2.jcc.DB2Sqlca;
Chapter 3. JDBC application programming
77

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents