IBM DB2 Manual page 94

Table of Contents

Advertisement

|
|
|
|
|
|
|
|
|
|
|
|
78
Application Programming Guide and Reference for Java
2. Optional: During a connection to a DB2 for z/OS or IBM Informix Dynamic
Server (IDS) data source, set the retrieveMessagesFromServerOnGetMessage
property to true if you want full message text from an
SQLException.getMessage call.
3. Optional: During a IBM Data Server Driver for JDBC and SQLJ type 2
connectivity connection to a DB2 for z/OS data source, set the
extendedDiagnosticLevel property to EXTENDED_DIAG_MESSAGE_TEXT (241) if you
want extended diagnostic information similar to the information that is
provided by the SQL GET DIAGNOSTICS statement from an
SQLException.getMessage call.
4. Put code that can generate an SQLException in a try block.
5. In the catch block, perform the following steps in a loop:
a. Test whether you have retrieved the last SQLException. If not, continue to
the next step.
b. Optional: For an SQL statement that executes on an IDS data source,
execute the com.ibm.db2.jcc.DB2Statement.getIDSSQLStatementOffSet
method to determine which columns have syntax errors.
DB2Statement.getIDSSQLStatementOffSet returns the offset into the SQL
statement of the first syntax error.
c. Optional: For an SQL statement that executes on an IDS data source, execute
the SQLException.getCause method to retrieve any ISAM error messages.
1) If the Throwable that is returned by SQLException.getCause is not null,
perform one of the following sets of steps:
v Issue SQLException.printStackTrace to print an error message that
includes the ISAM error message text. The ISAM error message text is
preceded by the string "Caused by:".
v Retrieve the error code and message text for the ISAM message:
a) Test whether the Throwable is an instance of an SQLException. If
so, retrieve the SQL error code from that SQLException.
b) Execute the Throwable.getMessage method to retrieve the text of
the ISAM message.
d. Check whether any IBM Data Server Driver for JDBC and SQLJ-only
information exists by testing whether the SQLException is an instance of
DB2Diagnosable. If so:
1) Cast the object to a DB2Diagnosable object.
2) Optional: Invoke the DB2Diagnosable.printTrace method to write all
SQLException information to a java.io.PrintWriter object.
3) Invoke the DB2Diagnosable.getThrowable method to determine
whether an underlying java.lang.Throwable caused the SQLException.
4) Invoke the DB2Diagnosable.getSqlca method to retrieve the DB2Sqlca
object.
5) Invoke the DB2Sqlca.getSqlCode method to retrieve an SQL error code
value.
6) Invoke the DB2Sqlca.getSqlErrmc method to retrieve a string that
contains all SQLERRMC values, or invoke the
DB2Sqlca.getSqlErrmcTokens method to retrieve the SQLERRMC
values in an array.
7) Invoke the DB2Sqlca.getSqlErrp method to retrieve the SQLERRP
value.
8) Invoke the DB2Sqlca.getSqlErrd method to retrieve the SQLERRD
values in an array.

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents