IBM Support

Stand alone Test Programs

Troubleshooting


Problem

Standalone and built-in sample programs to test connectivity for DB2 JDBC and CLI applications for troubleshooting.

Resolving The Problem

Legacy JDBC Driver in Type 2 mode (db2java.zip)

Support for this driver first removed in DB2 v10.1.

Sample Output


java LT2Test sample db2inst1 123456
userid is db2inst1
URL is: jdbc:db2:SAMPLE
Trying to connect using legacy JDBC driver in Type 2 Mode
Connected to database

Executing query
Retrieved row: Y
Finished retrieving all result rows
Disconnected from database

LT2Test.javaLT2Test.java

Universal JDBC Driver (db2jcc.jar/db2jcc4.jar)

Built-in Test Program



java com.ibm.db2.jcc.DB2Jcc -url jdbc:db2://localhost:50000/SAMPLE -user db2inst1 -password 123456 -tracing >trace.out

Stand-alone Sample Output

Database=SAMPLE

DB2 Server Hostname= localhost (127.0.0.1)

DB2 Port = 50,0000

User = db2inst1

Password 123456


java T4TestProg localhost:50000 sample db2inst1 123456 d://java//T4TestProg
URL is: jdbc:db2://localhost:50000/sample:traceLevel=-1;traceFile=/tmp/jcctrace
Trying to connect using JCC T4 driver
Connected to database

Executing query
Result set is not null, retrieving rows..

Row: Y
Finished retrieving all result rows
Disconnected from database

T4TestProg.javaT4TestProg.java

Universal JDBC Driver (db2jcc.jar/db2jcc4.jar) using 2 phase commit (XA)

Connects to two different databases SAMPLE1 and SAMPLE2 both located on same DB2 server then executes two SQL statements within the scope of one distributed transaction.

XASample.javaXASample.java

Built-in db2cli test program

UNIX: ~/sqllib/bin/db2cli or ~/sqllib/samples/ (older release of DB2)

Windows: C:\Program Files\IBM\SQLLIB\BIN


C:\db2v105\BIN>db2cli execsql -connstring "DATABASE=SAMPLE;HOSTNAME=localhost;PORT=50000;UID=db2inst1;PWD=123456"
-inputsql test.sql

IBM DATABASE 2 Interactive CLI Sample Program
(C) COPYRIGHT International Business Machines Corp. 1993,1996
All Rights Reserved
Licensed Materials - Property of IBM
US Government Users Restricted Rights - Use, duplication or
disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

> select count(*) from syscat.tables
FetchAll: Columns: 1
1
447
FetchAll: 1 rows fetched.
>

Where test.sql contains the query select count(*) from syscat.tables; delimited by semi-colon.

CLI test script



Modify the script
Modify cli_query.cli so it uses the correct database name, user id and password.

# Connect Information
# database name: sample
# user: db2inst1
# password: 123456

# Two methods to test connect
SQLConnect 1 sample sql_nts db2inst1 sql_nts 123456 sql_nts



Run the script
UNIX/Linux: <instance home>/sqllib/samples/cli/db2cli <cli_query.cli
Windows: <DB2 installation directory>\sqllib\bin\db2cli <cli_query.cli
Default installation directory on Windows is C:\Program Files\IBM\SQLLIB

Sample Output


db2cli < cli_query.cli<br>

IBM DATABASE 2 Interactive CLI Sample Program
(C) COPYRIGHT International Business Machines Corp. 1993,1996
All Rights Reserved
Licensed Materials - Property of IBM
US Government Users Restricted Rights - Use, duplication or
disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
> > > > > > > SQLAllocEnv: rc = 0 (SQL_SUCCESS)
CLI henv = 1, Test Driver henv = 1
> SQLAllocConnect: rc = 0 (SQL_SUCCESS)
CLI hdbc = 1, Test Driver hdbc = 1
> > > SQLConnect: rc = 0 (SQL_SUCCESS)
> > > > SQLAllocStmt: rc = 0 (SQL_SUCCESS)
CLI hstmt = 1, Test Driver hstmt = 1
> > SQLExecDirect: rc = 0 (SQL_SUCCESS)
> > > > > > > > > > > FetchAll: Columns: 1
IBMREQD
Y
FetchAll: 1 rows fetched.
> SQLMoreResults: rc = 100 (SQL_NO_DATA_FOUND)
> > SQLTransact: rc = 0 (SQL_SUCCESS)
> > SQLDisconnect: rc = 0 (SQL_SUCCESS)
SQLFreeConnect: rc = 0 (SQL_SUCCESS)
SQLFreeEnv: rc = 0 (SQL_SUCCESS)
> > >

cli_query.clicli_query.cli

[{"Product":{"code":"SSEPGG","label":"Db2 for Linux, UNIX and Windows"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Component":"Connectivity - Other","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"9.7;9.5;9.1;10.1;10.5;11.1","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Document Information

Modified date:
16 June 2018

UID

swg21991740