IBM DB2 Manual page 504

Table of Contents

Advertisement

488
Application Programming Guide and Reference for Java
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] Unable to " +
"force the connection to close");
printWriter.println("[TraceExample] Deadlocks " +
"could occur if the connection is not closed.");
com.ibm.db2.jcc.DB2ExceptionFormatter.printTrace(e, printWriter,
"[TraceExample]");
}
}
private static void sampleConnectWithURLUsingDriverManager()
{
java.sql.Connection c = null;
// This time, send the printWriter to a file.
java.io.PrintWriter printWriter = null;
try {
printWriter =
new java.io.PrintWriter(
new java.io.BufferedOutputStream(
new java.io.FileOutputStream("/temp/driverLog.txt"), 4096), true);
}
catch(java.io.FileNotFoundException e) {
java.lang.System.err.println("Unable to establish a print writer for trace");
java.lang.System.err.flush();
return;
}
try {
Class.forName("com.ibm.db2.jcc.DB2Driver");
}
catch(ClassNotFoundException e) {
printWriter.println("[TraceExample] " +
"IBM Data Server Driver for JDBC and SQLJ type 4 connectivity " +
"is not in the application classpath. Unable to load driver.");
printWriter.flush();
return;
}
// This URL describes the target data source for Type 4 connectivity.
// The traceLevel property is established through the URL syntax,
// and driver tracing is directed to file "/temp/driverLog.txt"
// The traceLevel property has type int. The constants
// com.ibm.db2.jcc.DB2BaseDataSource.TRACE_DRDA_FLOWS and
// com.ibm.db2.jcc.DB2BaseDataSource.TRACE_CONNECTS represent
// int values. Those constants cannot be used directly in the
// first getConnection parameter. Resolve the constants to their
// int values by assigning them to a variable. Then use the
// variable as the first parameter of the getConnection method.
String databaseURL =
"jdbc:db2://sysmvs1.stl.ibm.com:5021" +
"/sample:traceFile=/temp/driverLog.txt;traceLevel=" +
(com.ibm.db2.jcc.DB2BaseDataSource.TRACE_DRDA_FLOWS |
com.ibm.db2.jcc.DB2BaseDataSource.TRACE_CONNECTS) + ";";
// Set other properties
java.util.Properties properties = new java.util.Properties();
properties.setProperty("user", "myname");
properties.setProperty("password", "mypass");
try {
// This connection request is traced using trace level

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents