• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1672
  • Last Modified:

DB2 Client can Connect, but JDBC can't connect, why?

Server:WinXP Professional, DB2 Enterprise Server 8.1, IP: example).

I created a database"mydb" in the insistant"DB2" , and setup communications to TCP/IP, port:9999, service name:test, user:myuser  pass:mypass

I could connect with it from other PC's Db2 configure assistant with the IP, port, user and password, and I also test the JDBC connection in other PC's Db2 configure assistant. It connect successfully.

But When I use JDBC in Java program:
If I run the java on the server with the code:
   String url = "jdbc:db2:mydb";
   DriverManager.registerDriver(new COM.ibm.db2.jdbc.app.DB2Driver());
   Connection con = DriverManager.getConnection(url, "myuser", "mypass");
   It can connect to the database.

But If I chage the code to:
   String url = "jdbc:db2://11.138.161:9999/mydb";
   DriverManager.registerDriver(new COM.ibm.db2.jdbc.net.DB2Driver());
   Connection con = DriverManager.getConnection(url, "myuser", "mypass");
   It keep on connecting for quite a long time and dead, and have no chance to return an error.

I check the services on the XP. It show that "DB2 JDBC Applet Server" is started. It use "db2jds.exe to start the server. And I can't find the db2jstrt command in the DB2.

I don't know what's wrong. I've tried all the ways I could find. Could someone give me a help?



2 Solutions
If you are using a standalone program, you should use the app driver:

try {
} catch (Exception e) {

String url = "jdbc:db2:mydb";
Connection con = DriverManager.getConnection(url, "myuser", "mypass");

The database "mydb" should be cataloged using the Client Configuration Assistant. Make sure that you can connect to this database using the CLP on the client.

By the way, if you are using the net driver, I believe that the correct port to connect to is 6789. This is the port that the JDBC Applet Server is listening to.

try {
} catch (Exception e) {
String url = "jdbc:db2://";
Connection con = DriverManager.getConnection(url, "myuser", "mypass");
jamesyzhAuthor Commented:
Thanks for your help.
I installed the DB2 again and don't modify any configuration.
Then I could connect with the database in DB2 via JDBC.

I think one of the reason for the problem is that I setup the communication and modify the TCP/IP port to 9999 in DB2.  

But what confuse me is that why the chage of TCP/IP port will affect the DB2 JDBC Applet server.

I think you set up the DB2 instance to listen on port
9999. However, you left the port for the db2jd at the
default. When you were trying to connect using the
net driver, you specified the  port the instance was
listening on and not the one the db2jd was using.

For DB2 8.x the 'net' driver is deprecated but still
supported. I recommend to use the new type-4 'jcc' driver,
which is pure Java but doesn't need the db2jd any more,
because it speaks the native DB2 protocol.

Check out the manual 'Developing Enterprise Java Applications Using DB2 Version 8' for details on the new

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now