Table 19. Default autocommit modes for IDS data sources (continued)
Type of data source
Default autocommit mode
for local transactions
Default autocommit mode
for global transactions
Non-ANSI-compliant
database with logging
true false
Exceptions and warnings under the IBM Data Server Driver for JDBC
and SQLJ
In JDBC applications, SQL errors throw exceptions, which you handle using
try/catch blocks. SQL warnings do not throw exceptions, so you need to invoke
methods to check whether warnings occurred after you execute SQL statements.
The IBM Data Server Driver for JDBC and SQLJ provides the following classes and
interfaces, which provide information about errors and warnings.
SQLException
The SQLException class for handling errors. All JDBC methods throw an instance of
SQLException when an error occurs during their execution. According to the JDBC
specification, an SQLException object contains the following information:
v An int value that contains an error code. SQLException.getErrorCode retrieves
this value.
v A String object that contains the SQLSTATE, or null. SQLException.getSQLState
retrieves this value.
v A String object that contains a description of the error, or null.
SQLException.getMessage retrieves this value.
v A pointer to the next SQLException, or null. SQLException.getNextException
retrieves this value.
When a JDBC method throws a single SQLException, that SQLException might be
caused by an underlying Java exception that occurred when the IBM Data Server
Driver for JDBC and SQLJ processed the method. In this case, the SQLException
wraps the underlying exception, and you can use the SQLException.getCause
method to retrieve information about the error.
DB2Diagnosable
The IBM Data Server Driver for JDBC and SQLJ-only interface
com.ibm.db2.jcc.DB2Diagnosable extends the SQLException class. The
DB2Diagnosable interface gives you more information about errors that occur when
the data source is accessed. If the JDBC driver detects an error, DB2Diagnosable
gives you the same information as the standard SQLException class. However, if
the database server detects the error, DB2Diagnosable adds the following methods,
which give you additional information about the error:
getSqlca
Returns an DB2Sqlca object with the following information:
v An SQL error code
v The SQLERRMC values
v The SQLERRP value
v The SQLERRD values
v The SQLWARN values
Chapter 3. JDBC application programming 75