Compile the tool (e.g., javac jdbctest.java) to use it.
Compiling the tool verifies that the java compile/install environment is setup correctly on the target machine.
One of these drivers must be specified in the CLASSPATH since the tool dynamically loads a driver based on user input. [The tool prompts the user for that input].
The DB2 driver is typically in a jar file called: db2java.zip. This jar file has to be in the CLASSPATH if DB2 is used.
NOTE: Ensure you are specifying the correct db2java.zip file in your CLASSPATH.
Two db2java.zip files are available in the WebSphere Application Server environment. The db2java.zip file, located in the WebSphere\AppServer\lib directory, reflects the complimentary, limited-function version of DB2.
If your CLASSPATH points to this db2java.zip file, the jdbctest tool connection test will fail with error:
Unsatisfied link error SQL connect.
Your CLASSPATH must point to the db2java.zip file used by the full version DB2 product. This file is located in the SQLLIB\java directory.To verify that your CLASSPATH is the same as the one specified in the admin.config file, set up the CLASSPATH environment variable to match the production CLASSPATH in the admin.config file.
The Oracle driver is typically in a zip file called: classes111.zip.
The corresponding jar or zip file has to be added to the CLASSPATH for this tool to load the appropriate driver. This verifies that the database JDBC Driver is found and loadable.
It uses this information to connect to the specified database.
This verifies that connectivity to the database is possible using the DBURL specified. This also verifies that the userid/password provided to the tool, are correct.
This verifies that SQL statements are executed and results are displayed back to the user.
The best way to demonstrate the use of this tool is through examples.
Meaning of the text in the following examples:
NOTE: WebSphere Application Server must be installed before you can use this tool.
Compiling the tool:
javac jdbctest.java (compiles
this tool and produces several class files)
Do you want to invoke the tool with DB2 or Oracle? Choose your database.
Invoking the tool with DB2:
java jdbctest
JDBC Test starting...
Please respond:
1
- For DB2
2
- For Oracle
1
Loading jdbc driver: COM.ibm.db2.jdbc.app.DB2Driver
COM.ibm.db2.jdbc.app.DB2Driver was loaded successfully
Please enter connection URL, e.g:
jdbc:db2:dbname or dbname
was
Please enter userid for connection to jdbc:db2:wsa
guest
userid is: 'guest'
Please enter password =====>
WARNING: PASSWORD NOT HIDDEN <======
enter 'gui' instead of your password for a secure
GUI prompt) (if you enter the literal
characters "gui" you get a graphical password prompt)
guest
Connection Successful: COM.ibm.db2.jdbc.app.DB2Connection@201c70f
Connection took 120 milliseconds to complete
(time
it took to perform the database connect)
AutoCommit is: true
Create new statement...
Please enter sql statement to execute...(q to
quit)...(or maxconn to test maximum connections possible to database)
select * from ejsadmin.node_table
Operation took 2 milliseconds to complete
Just tried true = stmt.execute("select * from
ejsadmin.node_table"); (true means that
there additional results to extract)
Getting result set...
4 column(s) in result
INSTANCE_ID TYPE_ID NAME
DEPLOYEDJARDIR
-----------------------------------
48,12,asdasd,e:\wsa\deployedEJBs
161,12,hany,/usr/WebSphere/AppServer/deployedEJBs
Create new statement...
Please enter sql statement to execute...(q to
quit)...(or maxconn to test maximum connections possible to database)
q
Ok, quitting!
Invoking the tool with Oracle:
java jdbctest
JDBC Test starting...
Please respond:
1
- For DB2
2
- For Oracle
2
Loading jdbc driver: oracle.jdbc.driver.OracleDriver
oracle.jdbc.driver.OracleDriver was loaded successfully
Please enter connection URL, e.g:
jdbc:oracle:thin:@hostname:1521:dbname or thin:@hostname:1521:dbname
thin:@pig:1521:orcl
Please enter userid for connection to jdbc:oracle:thin:@pig:1521:orcl
hany
userid is: 'hany'
Please enter password =====>
WARNING: PASSWORD NOT HIDDEN <======
enter 'gui' instead of your password for a secure
GUI prompt) (if you enter the literal
characters "gui" you get a graphical password prompt)
hany
Connection Successful: oracle.jdbc.driver.OracleConnection@201c665
Connection took 1462 milliseconds to complete
(time
it took to perform the database connect)
AutoCommit is: true
Create new statement...
Please enter sql statement to execute...(q to
quit)...(or maxconn to test maximum connections possible to database)
select * from person
Operation took 20 milliseconds to complete
Just tried true = stmt.execute("select * from
person"); (true means that there additional
results to extract)
Getting result set...
3 column(s) in result
ID NAME AGE
-----------------------------------
1,Hany Salem,77
22,Barton,55
Create new statement...
Please enter sql statement to execute...(q to
quit)...(or maxconn to test maximum connections possible to database)
q
Ok, quitting!