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

Table of Contents

Advertisement

Handling an SQLWarning under the IBM Data Server Driver for
JDBC and SQLJ
Unlike SQL errors, SQL warnings do not cause JDBC methods to throw exceptions.
Instead, the Connection, Statement, PreparedStatement, CallableStatement, and
ResultSet classes contain getWarnings methods, which you need to invoke after
you execute SQL statements to determine whether any SQL warnings were
generated.
The basic steps for retrieving SQL warning information are:
1. Optional: During connection to the database server, set properties that affect
SQLWarning objects.
If you want full message text from a DB2 for z/OS or IBM Informix Dynamic
Server (IDS) data source when you execute SQLWarning.getMessage calls, set the
retrieveMessagesFromServerOnGetMessage property to true.
If you are using IBM Data Server Driver for JDBC and SQLJ type 2 connectivity
to a DB2 for z/OS data source, and you want extended diagnostic information
that is similar to the information that is provided by the SQL GET
DIAGNOSTICS statement when you execute SQLWarning.getMessage calls, set
the extendedDiagnosticLevel property to EXTENDED_DIAG_MESSAGE_TEXT (241).
2. Immediately after invoking a method that connects to a database server or
executes an SQL statement, invoke the getWarnings method to retrieve an
SQLWarning object.
3. Perform the following steps in a loop:
a. Test whether the SQLWarning object is null. If not, continue to the next step.
b. Invoke the SQLWarning.getMessage method to retrieve the warning
description.
c. Invoke the SQLWarning.getSQLState method to retrieve the SQLSTATE
value.
d. Invoke the SQLWarning.getErrorCode method to retrieve the error code
value.
e. If you want DB2-specific warning information, perform the same steps that
you perform to get DB2-specific information for an SQLException.
f. Invoke the SQLWarning.getNextWarning method to retrieve the next
SQLWarning.
The following code illustrates how to obtain generic SQLWarning information. The
numbers to the right of selected statements correspond to the previously-described
steps.
Chapter 3. JDBC application programming
81

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents