accessed. If the JDBC driver detects an error, this SQLException class gives you
the same information as the standard SQLException class. However, if DB2
detects the error, this SQLException class gives you the standard information,
along with the contents of the SQLCA that DB2 returns. If you plan to run your
JDBC applications only on a system that uses the DB2 Universal JDBC Driver,
you can use this extended SQLException class.
Under the DB2 Universal JDBC Driver, SQLExceptions from DB2 implement the
com.ibm.db2.jcc.DB2Diagnosable
interface. An SQLException from DB2
contains the following information:
A
java.lang.Throwable
object that caused the SQLException or null if no such
object exists. The
java.lang.Throwable
class is the superclass of all errors
and exceptions in the Java language.
The information that is provided by a standard SQLException
An object of DB2 defined type
DB2Sqlca
that contains the SQLCA. This
object contains the following objects:
An INT value that contains an SQL error code
A String object that contains the SQLERRMC values
A String object that contains the SQLERRP value
An array of INT values that contains the SQLERRD values
An array of CHAR values that contains the SQLWARN values
A String object that contains the SQLSTATE
The basic steps for handling an SQLException in a JDBC program that runs
under the DB2 Universal JDBC Driver are:
1. Import the required classes for DB2 UDB error handling,
com.ibm.db2.jcc.DB2Diagnosable
for getting diagnostic data, and
com.ibm.db2.jcc.DB2Sqlca
for error messages.
2. In your code catch
SQLException
and use it to get SQLCA. This is allowed
only if the exception thrown is an instance of the
DB2Diagnosable
class.
3. Once you have
DB2Sqlca
, it can be used to get SQLCODE, messages, SQL
errors, and winnings as shown in Example 7 52.
Example 7 52 Processing an SQLException under the DB2 Universal JDBC Driver
import com.ibm.db2.jcc.DB2Diagnosable;
import com.ibm.db2.jcc.DB2Sqlca;
try {
// Code that could throw SQLExceptions
} catch(SQLException sqle) {
while(sqle != null) {
if (sqle instanceof DB2Diagnosable) {
DB2Sqlca sqlca = ((DB2Diagnosable)sqle).getSqlca();
Chapter 7. Application porting
217
footer
Our partners:
PHP: Hypertext Preprocessor Cheap Web Hosting
JSP Web Hosting
Ontario Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Java Hosting
Cheapest Hosting
Visionwebhosting.net Business web hosting division of Vision Web Hosting Inc.. All rights reserved