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

Posted on 2003-03-31
Medium Priority
Last Modified: 2012-06-27
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?



Question by:jamesyzh
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

yongsing earned 152 total points
ID: 8242583
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");

Author Comment

ID: 8242806
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.


Assisted Solution

mglxxx earned 148 total points
ID: 8243606
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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question