Applications that access the CLI and DB2® JDBC drivers can make use of the CLI and DB2 JDBC trace facilities. These utilities record all function calls made by the CLI or DB2 JDBC drivers to a log file which is useful for problem determination.
The CLI and DB2 JDBC trace facilities automatically use the application's process ID and thread sequence number to name the trace files when the TracePathName and JDBCTracePathName keywords have been set. For example, a CLI trace of an application with three threads might generate the following CLI trace files: 100390.0, 100390.1, 100390.2.
1 [ Process: 1227, Thread: 1024 ]
2 [ Date, Time: 01-27-2002 13:46:07.535211 ]
3 [ Product: QDB2/LINUX 7.1.0 ]
4 [ Level Identifier: 02010105 ]
5 [ CLI Driver Version: 07.01.0000 ]
6 [ Informational Tokens: "DB2 v7.1.0","n000510","" ]
7 SQLAllocEnv( phEnv=&bffff684 )
8 ---> Time elapsed - +9.200000E-004 seconds
9 SQLAllocEnv( phEnv=0:1 )
10 <--- SQL_SUCCESS Time elapsed - +7.500000E-004 seconds
11 SQLAllocConnect( hEnv=0:1, phDbc=&bffff680 )
12 ---> Time elapsed - +2.334000E-003 seconds
13 SQLAllocConnect( phDbc=0:1 )
14 <--- SQL_SUCCESS Time elapsed - +5.280000E-004 seconds
15 SQLSetConnectOption( hDbc=0:1, fOption=SQL_ATTR_AUTOCOMMIT, vParam=0 )
16 ---> Time elapsed - +2.301000E-003 seconds
17 SQLSetConnectOption( )
18 <--- SQL_SUCCESS Time elapsed - +3.150000E-004 seconds
19 SQLConnect( hDbc=0:1, szDSN="SAMPLE", cbDSN=-3, szUID="", cbUID=-3,
szAuthStr="", cbAuthStr=-3 )
20 ---> Time elapsed - +7.000000E-005 seconds
21 ( DBMS NAME="DB2/LINUX", Version="07.01.0000", Fixpack="0x22010105" )
22 SQLConnect( )
23 <--- SQL_SUCCESS Time elapsed - +5.209880E-001 seconds
24 ( DSN=""SAMPLE"" )
25 ( UID=" " )
26 ( PWD="*" )
In the prior trace example, notice that there are two entries for each CLI function call (for example, lines 19-21 and 22-26 for the SQLConnect() function call). This is always the case in CLI traces. The first entry shows the input parameter values passed to the function call while the second entry shows the function output parameter values and return code returned to the application.
The above trace example shows that the SQLAllocEnv() function successfully allocated an environment handle ( phEnv=0:1 ) at line 9. That handle was then passed to the SQLAllocConnect() function which successfully allocated a database connection handle ( phDbc=0:1 ) as of line 13. Next, the SQLSetConnectOption() function was used to set the phDbc=0:1 connection's SQL_ATTR_AUTOCOMMIT attribute to SQL_AUTOCOMMIT_OFF ( vParam=0 ) at line 15. Finally, SQLConnect() was called to connect to the target database ( SAMPLE ) at line 19.
( Application Codepage=819, Database Codepage=819,
Char Send/Recv Codepage=819, Graphic Send/Recv Codepage=819,
Application Char Codepage=819, Application Graphic Codepage=819 )
This
would mean the application and the database server were using the
same code page ( 819 ).( PATCH2="27,28" )
27 SQLAllocStmt( hDbc=0:1, phStmt=&bffff684 )
28 ---> Time elapsed - +1.868000E-003 seconds
29 SQLAllocStmt( phStmt=1:1 )
30 <--- SQL_SUCCESS Time elapsed - +6.890000E-004 seconds
31 SQLExecDirect( hStmt=1:1, pszSqlStr="CREATE TABLE GREETING (MSG
VARCHAR(10))", cbSqlStr=-3 )
32 ---> Time elapsed - +2.863000E-003 seconds
33 ( StmtOut="CREATE TABLE GREETING (MSG VARCHAR(10))" )
34 SQLExecDirect( )
35 <--- SQL_SUCCESS Time elapsed - +2.387800E-002 seconds
In
the above trace example, the database connection handle ( phDbc=0:1
) was used to allocate a statement handle ( phStmt=1:1 ) at line 29.
An unprepared SQL statement was then executed on that statement handle
at line 31. If the TraceComm=1 keyword had been set in the db2cli.ini file,
the SQLExecDirect() function
call trace entries would have shown additional client-server communication
information as follows: SQLExecDirect( hStmt=1:1, pszSqlStr="CREATE TABLE GREETING (MSG
VARCHAR(10))", cbSqlStr=-3 )
---> Time elapsed - +2.876000E-003 seconds
( StmtOut="CREATE TABLE GREETING (MSG VARCHAR(10))" )
sqlccsend( ulBytes - 232 )
sqlccsend( Handle - 1084869448 )
sqlccsend( ) - rc - 0, time elapsed - +1.150000E-004
sqlccrecv( )
sqlccrecv( ulBytes - 163 ) - rc - 0, time elapsed - +2.243800E-002
SQLExecDirect( )
<--- SQL_SUCCESS Time elapsed - +2.384900E-002 seconds
Notice
the additional sqlccsend() and sqlccrecv() function call information
in this trace entry. The sqlccsend() call information reveals how
much data was sent from the client to the server, how long the transmission
took, and the success of that transmission ( 0 = SQL_SUCCESS ). The
sqlccrecv() call information then reveals how long the client waited
for a response from the server and the amount of data included in
the response. Often, multiple statement handles will appear in the CLI trace. By paying close attention to the statement handle identifier, one can easily follow the execution path of a statement handle independent of all other statement handles appearing in the trace.
36 SQLAllocStmt( hDbc=0:1, phStmt=&bffff684 )
37 ---> Time elapsed - +1.532000E-003 seconds
38 SQLAllocStmt( phStmt=1:2 )
39 <--- SQL_SUCCESS Time elapsed - +6.820000E-004 seconds
40 SQLPrepare( hStmt=1:2, pszSqlStr="INSERT INTO GREETING VALUES ( ? )",
cbSqlStr=-3 )
41 ---> Time elapsed - +2.733000E-003 seconds
42 ( StmtOut="INSERT INTO GREETING VALUES ( ? )" )
43 SQLPrepare( )
44 <--- SQL_SUCCESS Time elapsed - +9.150000E-004 seconds
45 SQLBindParameter( hStmt=1:2, iPar=1, fParamType=SQL_PARAM_INPUT,
fCType=SQL_C_CHAR, fSQLType=SQL_CHAR, cbColDef=14,
ibScale=0, rgbValue=&080eca70, cbValueMax=15,
pcbValue=&080eca4c )
46 ---> Time elapsed - +4.091000E-003 seconds
47 SQLBindParameter( )
48 <--- SQL_SUCCESS Time elapsed - +6.780000E-004 seconds
49 SQLExecute( hStmt=1:2 )
50 ---> Time elapsed - +1.337000E-003 seconds
51 ( iPar=1, fCType=SQL_C_CHAR, rgbValue="Hello World!!!", pcbValue=14,
piIndicatorPtr=14 )
52 SQLExecute( )
53 <--- SQL_ERROR Time elapsed - +5.951000E-003 seconds
In
the above trace example, the database connection handle ( phDbc=0:1
) was used to allocate a second statement handle ( phStmt=1:2 ) at
line 38. An SQL statement with one parameter marker was then prepared
on that statement handle at line 40. Next, an input parameter ( iPar=1
) of the appropriate SQL type ( SQL_CHAR ) was bound to the parameter
marker at line 45. Finally, the statement was executed at line 49.
Notice that both the contents and length of the input parameter (
rgbValue="Hello World!!!", pcbValue=14 ) are displayed in the trace
on line 51.54 SQLError( hEnv=0:1, hDbc=0:1, hStmt=1:2, pszSqlState=&bffff680,
pfNativeError=&bfffee78, pszErrorMsg=&bffff280,
cbErrorMsgMax=1024, pcbErrorMsg=&bfffee76 )
55 ---> Time elapsed - +1.512000E-003 seconds
56 SQLError( pszSqlState="22001", pfNativeError=-302, pszErrorMsg="[IBM][CLI
Driver][DB2/LINUX] SQL0302N The value of a host variable in the EXECUTE
or OPEN statement is too large for its corresponding use.
SQLSTATE=22001", pcbErrorMsg=157 )
57 <--- SQL_SUCCESS Time elapsed - +8.060000E-004 seconds
The
error message returned at line 56 contains the DB2 native error code that was generated ( SQL0302N
), the sqlstate that corresponds to that code ( SQLSTATE=22001 ) and
a brief description of the error. In this example, the source of
the error is evident: on line 49, the application is trying to insert
a string with 14 characters into a column defined as VARCHAR(10) on
line 31.SQLDisconnect( hDbc=0:1 )
---> Time elapsed - +1.501000E-003 seconds
sqlccsend( ulBytes - 72 )
sqlccsend( Handle - 1084869448 )
sqlccsend( ) - rc - 0, time elapsed - +1.080000E-004
sqlccrecv( )
sqlccrecv( ulBytes - 27 ) - rc - 0, time elapsed - +1.717950E-001
( Unretrieved error message="SQL0302N The value of a host variable in the
EXECUTE or OPEN statement is too large for its corresponding use.
SQLSTATE=22001" )
SQLDisconnect( )
<--- SQL_SUCCESS Time elapsed - +1.734130E-001 seconds
58 SQLTransact( hEnv=0:1, hDbc=0:1, fType=SQL_ROLLBACK )
59 ---> Time elapsed - +6.085000E-003 seconds
60 ( ROLLBACK=0 )
61 SQLTransact( )
<--- SQL_SUCCESS Time elapsed - +2.220750E-001 seconds
62 SQLDisconnect( hDbc=0:1 )
63 ---> Time elapsed - +1.511000E-003 seconds
64 SQLDisconnect( )
65 <--- SQL_SUCCESS Time elapsed - +1.531340E-001 seconds
66 SQLFreeConnect( hDbc=0:1 )
67 ---> Time elapsed - +2.389000E-003 seconds
68 SQLFreeConnect( )
69 <--- SQL_SUCCESS Time elapsed - +3.140000E-004 seconds
70 SQLFreeEnv( hEnv=0:1 )
71 ---> Time elapsed - +1.129000E-003 seconds
72 SQLFreeEnv( )
73 <--- SQL_SUCCESS Time elapsed - +2.870000E-004 seconds
1 ========================================================
2 | Trace beginning on 2002-1-28 7:21:0.19
3 ========================================================
4 System Properties:
5 ------------------
6 user.language = en
7 java.home = c:\Program Files\SQLLIB\java\jdk\bin\..
8 java.vendor.url.bug =
9 awt.toolkit = sun.awt.windows.WToolkit
10 file.encoding.pkg = sun.io
11 java.version = 1.1.8
12 file.separator = \
13 line.separator =
14 user.region = US
15 file.encoding = Cp1252
16 java.compiler = ibmjitc
17 java.vendor = IBM Corporation
18 user.timezone = EST
19 user.name = db2user
20 os.arch = x86
21 java.fullversion = JDK 1.1.8 IBM build n118p-19991124 (JIT ibmjitc
V3.5-IBMJDK1.1-19991124)
22 os.name = Windows NT
23 java.vendor.url = http://www.ibm.com/
24 user.dir = c:\Program Files\SQLLIB\samples\java
25 java.class.path =
.:C:\Program Files\SQLLIB\lib;C:\Program Files\SQLLIB\java;
C:\Program Files\SQLLIB\java\jdk\bin\
26 java.class.version = 45.3
27 os.version = 5.0
28 path.separator = ;
29 user.home = C:\home\db2user
30 ----------------------------------------
31 jdbc.app.DB2Driver -> DB2Driver() (2002-1-28 7:21:0.29)
32 | Loaded db2jdbc from java.library.path
33 jdbc.app.DB2Driver <- DB2Driver() [Time Elapsed = 0.01]
34 DB2Driver - connect(jdbc:db2:sample)
35 jdbc.app.DB2ConnectionTrace -> connect( sample, info, db2driver, 0, false )
(2002-1-28 7:21:0.59)
36 | 10: connectionHandle = 1
37 jdbc.app.DB2ConnectionTrace <- connect() [Time Elapsed = 0.16]
38 jdbc.app.DB2ConnectionTrace -> DB2Connection (2002-1-28 7:21:0.219)
39 | source = sample
40 | Connection handle = 1
41 jdbc.app.DB2ConnectionTrace <- DB2Connection
In
the above trace example, a request to load the DB2 JDBC driver was made on line 31. This request
returned successfully as reported on line 33.The DB2 JDBC trace facility uses specific Java classes to capture the trace information. In the above trace example, one of those trace classes, DB2ConnectionTrace, has generated two trace entries numbered 35-37 and 38-41.
Line 35 shows the connect() method being invoked and the input parameters to that method call. Line 37 shows that the connect() method call has returned successfully while line 36 shows the output parameter of that call ( Connection handle = 1 ).
42 jdbc.app.DB2ConnectionTrace -> createStatement() (2002-1-28 7:21:0.219)
43 | Connection handle = 1
44 | jdbc.app.DB2StatementTrace -> DB2Statement( con, 1003, 1007 )
(2002-1-28 7:21:0.229)
45 | jdbc.app.DB2StatementTrace <- DB2Statement() [Time Elapsed = 0.0]
46 | jdbc.app.DB2StatementTrace -> DB2Statement (2002-1-28 7:21:0.229)
47 | | Statement handle = 1:1
48 | jdbc.app.DB2StatementTrace <- DB2Statement
49 jdbc.app.DB2ConnectionTrace <- createStatement - Time Elapsed = 0.01
50 jdbc.app.DB2StatementTrace -> executeQuery(SELECT * FROM EMPLOYEE WHERE
empno = 000010) (2002-1-28 7:21:0.269)
51 | Statement handle = 1:1
52 | jdbc.app.DB2StatementTrace -> execute2( SELECT * FROM EMPLOYEE WHERE
empno = 000010 ) (2002-1-28 7:21:0.269)
52 | | jdbc.DB2Exception -> DB2Exception() (2002-1-28 7:21:0.729)
53 | | | 10: SQLError = [IBM][CLI Driver][DB2/NT] SQL0401N The data types of
the operands for the operation "=" are not compatible.
SQLSTATE=42818
54 | | | SQLState = 42818
55 | | | SQLNativeCode = -401
56 | | | LineNumber = 0
57 | | | SQLerrmc = =
58 | | jdbc.DB2Exception <- DB2Exception() [Time Elapsed = 0.0]
59 | jdbc.app.DB2StatementTrace <- executeQuery - Time Elapsed = 0.0
On
line 42 and 43, the DB2ConnectionTrace class reported that the JDBC
createStatement() method had been called with connection handle 1.
Within that method, the internal method DB2Statement() was called
as reported by another DB2 JDBC
trace facility class, DB2StatementTrace. Notice that this internal
method call appears 'nested' in the trace entry. Lines 47-49 show
that the methods returned successfully and that statement handle 1:1
was allocated.On line 50, an SQL query method call is made on statement 1:1, but the call generates an exception at line 52. The error message is reported on line 53 and contains the DB2 native error code that was generated ( SQL0401N ), the sqlstate that corresponds to that code ( SQLSTATE=42818 ) and a brief description of the error. In this example, the error results because the EMPLOYEE.EMPNO column is defined as CHAR(6) and not an integer value as assumed in the query.