This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JDBC and the fly likes Access to DB2 UDB thru JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Access to DB2 UDB thru JDBC" Watch "Access to DB2 UDB thru JDBC" New topic
Author

Access to DB2 UDB thru JDBC

Bala Ramachandran
Greenhorn

Joined: Aug 20, 2001
Posts: 12
Hi,
I need some help in figuring out the JDBC access to DB2.
I am trying to acces a DB2 UDB database server from a stand-alone Jaba application, thru JDBC using "COM.ibm.db2.jdbc.net.DB2Driver". I get the following exception:
COM.ibm.db2.jdbc.DB2Exception: [IBM][JDBC Driver] CLI0616E Error opening socket. SQLSTATE=08S01.
When I try it with the driver "CON.ibm.db2.jdbc.app.DB2Driver", I get the exception:
java.sql.SQLException: No suitable driver
I have installed the DB2 client on my machine and I have the db2java.zip included in my classpath.
Actually I need to use this is a JSp/servlet. But I thought I would first test it in a simple Java program.
Can anyone help me ?
Thank You
Bala.
Nathanael Ulrick
Greenhorn

Joined: Jul 17, 2001
Posts: 22
To use the net driver, you need to have db2jstrt running on the host machine. The default port then would be 6789, although you can specify a different port. I've read somewhere that you'd need db2jstrt running on the client with the same port as well -- I doubt this is the case, but try it if you get stuck. Also, the copy of db2java.zip has to be the same as the one on the server.
If you use the app driver, the client config assistant needs to know about the server, and the port that you'd use won't be the same as the above (usually 50000, if you've only got one instance of db2.)
By the way, the JDBC drivers on 6 and 7 are buggy, so get the latest fixpack (and don't forget to keep db2java.zip in sync.)
You might find a 3rd party driver, eg from HiT Software much simpler to use.
Bala Ramachandran
Greenhorn

Joined: Aug 20, 2001
Posts: 12
Originally posted by Nathanael Ulrick:
To use the net driver, you need to have db2jstrt running on the host machine. The default port then would be 6789, although you can specify a different port. I've read somewhere that you'd need db2jstrt running on the client with the same port as well -- I doubt this is the case, but try it if you get stuck. Also, the copy of db2java.zip has to be the same as the one on the server.
If you use the app driver, the client config assistant needs to know about the server, and the port that you'd use won't be the same as the above (usually 50000, if you've only got one instance of db2.)
By the way, the JDBC drivers on 6 and 7 are buggy, so get the latest fixpack (and don't forget to keep db2java.zip in sync.)
You might find a 3rd party driver, eg from HiT Software much simpler to use.

Hi,
Thanks for the reply. I have the db2java.zip in the Sun machine (which is the client). Does it mean I need the db2java.zip in the database server too ? If so, what version should I use. The database server is a IBM SP2 running on AIX. Will the version of db2java.zip be compatible with the db2java.zip in the Sun machine ?
Also, in the connection URL should I use 50000 or 6789 ?
I appreciate your help.
Thanks
Bala.
Nathanael Ulrick
Greenhorn

Joined: Jul 17, 2001
Posts: 22
Since you'll be running a servlet, the net driver would probably be the most appropriate....
db2java.zip should already be on the server, in sqllib/java
I would copy this file to the client. It should work even if the two machines are different types. Include this file in your classpath.
Also, you have to execute db2jstrt on the server. If you do not specify any arguments, this will open port 6789.
Connect with the net driver using a url which should look something like this:
jdbc:db2:yourserver:6789/yourschema
Bala Ramachandran
Greenhorn

Joined: Aug 20, 2001
Posts: 12
Originally posted by Nathanael Ulrick:
Since you'll be running a servlet, the net driver would probably be the most appropriate....
db2java.zip should already be on the server, in sqllib/java
I would copy this file to the client. It should work even if the two machines are different types. Include this file in your classpath.
Also, you have to execute db2jstrt on the server. If you do not specify any arguments, this will open port 6789.
Connect with the net driver using a url which should look something like this:
jdbc:db2:yourserver:6789/yourschema

Hi,
Thanks a lot for your help. I confirmed that the server has db2java.zip and then I ran db2jstrt on the server. I was able to get past the problem.
Thanks
Bala.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Access to DB2 UDB thru JDBC