Handling Sql Warnings In An Sqlj Application - IBM DB2 Manual

Table of Contents

Advertisement

Related reference
"Error codes issued by the IBM Data Server Driver for JDBC and SQLJ" on
page 382
"SQLSTATEs issued by the IBM Data Server Driver for JDBC and SQLJ" on
page 388

Handling SQL warnings in an SQLJ application

Other than a +100 SQL error code on a SELECT INTO statement, DB2 warnings do
not throw SQLExceptions. To handle DB2 warnings, you need to give the program
access to the java.sql.SQLWarning class.
If you want to retrieve DB2-specific information about a warning, you also need to
give the program access to the com.ibm.db2.jcc.DB2Diagnosable interface and the
com.ibm.db2.jcc.DB2Sqlca class. Then follow these steps:
1. Set up an execution context for that SQL clause. See "Control the execution of
SQL statements in SQLJ" for information on how to set up an execution
context.
2. To check for a DB2 warning, invoke the getWarnings method after you execute
an SQLJ clause.
getWarnings returns the first SQLWarning object that an SQL statement
generates. Subsequent SQLWarning objects are chained to the first one.
3. To retrieve DB2-specific information from the SQLWarning object with the IBM
Data Server Driver for JDBC and SQLJ, follow the instructions in "Handle an
SQLException under the IBM Data Server Driver for JDBC and SQLJ".
The following example demonstrates how to retrieve an SQLWarning object for an
SQL clause with execution context execCtx. The numbers to the right of selected
statements correspond to the previously-described steps.
ExecutionContext execCtx=myConnCtx.getExecutionContext();
SQLWarning sqlWarn;
...
#sql [myConnCtx,execCtx] {SELECT LASTNAME INTO :empname
FROM EMPLOYEE WHERE EMPNO='000010'};
if ((sqlWarn = execCtx.getWarnings()) != null)
System.out.println("SQLWarning " + sqlWarn);
Related concepts
"Example of a simple SQLJ application" on page 101
"SQL statement execution in SQLJ applications" on page 112
Related tasks
"Handling an SQLException under the IBM Data Server Driver for JDBC and
SQLJ" on page 77
"Controlling the execution of SQL statements in SQLJ" on page 142
"Handling SQL errors in an SQLJ application" on page 154
Related reference
"DB2Diagnosable interface" on page 344
"DB2Sqlca class" on page 353
// Get default execution context from
// connection context
Chapter 4. SQLJ application programming
1
2
155

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents