IBM DB2 Manual page 503

Table of Contents

Advertisement

}
catch(java.sql.SQLException e) {
com.ibm.db2.jcc.DB2ExceptionFormatter.printTrace(e,
printWriter, "[TraceExample]");
}
finally {
cleanup(c, printWriter);
printWriter.flush();
}
}
// If the code ran successfully, the connection should
// already be closed. Check whether the connection is closed.
// If so, just return.
// If a failure occurred, try to roll back and close the connection.
private static void cleanup(java.sql.Connection c,
java.io.PrintWriter printWriter)
{
if(c == null) return;
try {
if(c.isClosed()) {
printWriter.println("[TraceExample] " +
"The connection was successfully closed");
return;
}
// If we get to here, something has gone wrong.
// Roll back and close the connection.
printWriter.println("[TraceExample] Rolling back the connection");
try {
c.rollback();
}
catch(java.sql.SQLException e) {
printWriter.println("[TraceExample] " +
"Trapped the following java.sql.SQLException while trying to roll back:");
com.ibm.db2.jcc.DB2ExceptionFormatter.printTrace(e, printWriter,
"[TraceExample]");
printWriter.println("[TraceExample] " +
"Unable to roll back the connection");
}
catch(java.lang.Throwable e) {
printWriter.println("[TraceExample] Trapped the " +
"following java.lang.Throwable while trying to roll back:");
com.ibm.db2.jcc.DB2ExceptionFormatter.printTrace(e,
printWriter, "[TraceExample]");
printWriter.println("[TraceExample] Unable to " +
"roll back the connection");
}
// Close the connection
printWriter.println("[TraceExample] Closing the connection");
try {
c.close();
}
catch(java.sql.SQLException e) {
printWriter.println("[TraceExample] Exception while " +
"trying to close the connection");
printWriter.println("[TraceExample] Deadlocks could " +
"occur if the connection is not closed.");
com.ibm.db2.jcc.DB2ExceptionFormatter.printTrace(e, printWriter,
"[TraceExample]");
}
catch(java.lang.Throwable e) {
printWriter.println("[TraceExample] Throwable caught " +
"while trying to close the connection");
Chapter 15. Problem diagnosis with the IBM Data Server Driver for JDBC and SQLJ
487

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents