Results 1 to 12 of 12
  1. #1
    Join Date
    Aug 2003
    Posts
    11

    Unanswered: DB2 JDBC Connection hangs

    Hello

    I am trying to use the JDBC driver provided by IBM for DB2 to connect to a remote server. I am using Jbuilder 7 to write the application. However, it seems that the application just keeps trying to connect for a very long time but with no response.

    Here's a part of the code:
    ------------------------------
    try{
    Class.forName("COM.ibm.db2.jdbc.net.DB2Driver").ne wInstance();
    Connection con = DriverManager.getConnection("jdbc:db2://host/dbname", "db2user", "db2pwd");
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("QUERYSTATEMENT");
    System.out.println(rs.getMetaData().getColumnCount ());
    con.close();
    }
    catch (Exception ex) {
    ex.printStackTrace();
    }
    ------------------------------

    It hangs at the line Connection con = DriverManager.getConnection(...);.

    The remote server is running on DB2 v7.2.

    Does anyone have a clue as to what is happening? I would greatly appreciate any help I can get. Thanks!

  2. #2
    Join Date
    Aug 2003
    Posts
    11
    Hello

    I did a little bit more fiddling and it works now. I will use the driver in the com.ibm.db2.jcc package instead. The new code looks like that -

    -----------------------------------------
    try{
    Class.forName("COM.ibm.db2.jcc.DB2Driver").newInst ance();
    Connection con = DriverManager.getConnection("jdbc:db2://host/dbname", "db2user", "db2pwd");
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("QUERYSTATEMENT");
    System.out.println(rs.getMetaData().getColumnCount ());
    con.close();
    }
    catch (Exception ex) {
    ex.printStackTrace();
    }
    ----------------------------------------

    Does anyone know what the difference between the COM.ibm.db2.jdbc.net.DB2Driver and the com.ibm.db2.jcc.DB2Driver classes is?

    By the way, my client is running on v8.0 and the UDB2 server is on v7.2.5. Will this code work on a client that is not running the DB2 client software (i.e. standalone) or will I have to bind the database tables on the new client as well? Cuz I had to bind the tables on this client machine to get the jcc driver to work.

    Thanks!

  3. #3
    Join Date
    Dec 2002
    Posts
    134
    jcc is new type 4 driver introduced by IBM in 8.1, net - is old, depricated in 8.1. type 3 driver.
    The main difference between jcc and net - jcc talks to the db2 directly, while net talks to the intermidiate daemon db2jd (on a different port).

    As far as I remember, you must use exactly the same version of the net driver and target db (even fixpacks must be identical, otherwise behaviour is unpredicatble)

    Both net and jcc do not require client installation. You need client for the app driver (type 2)

    regards,
    dmitri

  4. #4
    Join Date
    Sep 2002
    Location
    Pinellas County Florida
    Posts
    20
    It's interesting that the jcc driver with your client works with your 7.2 database. The documentation I've read led me to believe that this would not work.

    If the all-Java version works, then your worries are over. The all-Java version replaces the old Type 2 and Type 3 drivers. It is kind of a hybrid between them. If it can use the CLI (call-level interface) it will, but if not it will try the network approach.

    The Type 2 driver requires that the host running your Java application has the appropriate UDB Client installed locally. This client allows applications (Java & non-Java alike) to access a database, even a remote database, using CLI, which uses faster native methods.

    The Type 3 driver does not require CLI access. It only requires a TCP/IP connection to the DB host. This makes it ideal for applets using HTTP.

    The DB host (the actual machine on which the database is loaded) must be running a program called db2jd, which is a daemon that handles remote DB requests. You start this daemon on the host machine by running a script (or batch file) called db2jstrt. It takes one optional parameter which is the TCP/IP port number on which the daemon will listen for DB requests. By default, this port is 6789.

    My guess is that when you were first trying the "net" driver, this daemon was not running. I had a tricky problem last week where I started this daemon under the wrong Aix user. Then when I tried to access a database, my connections were refused because the daemon listening on that port, the one running under the wrong user, did not have access to the database I was trying to connect to.

    To solve this problem, I had to kill the db2jd process, which freed up the port. Then I restarted the daemon under the right user and my connections went through.

    Whenever, possible try to use the Type 2 rather than the Type 3, because it's much faster. However, the new "universal" all-java driver you are using is the best solution, assuming you eventually get your Client and Hosts working on version UDB 8.1.

    The driver connect string for the Type 2 driver is exactly the same as for the Type 3 driver you were using, except substitute the string "app" for the string "net". Think "app" for application, "net" for internet.

  5. #5
    Join Date
    Aug 2003
    Posts
    11
    Hello guys

    Unfortunately, I wasn't able to touch this project until quite recently again for some time because one of the servers over here crashed and my supervisor and I had a whale of a time restoring everything back in order.

    Anyway, the JCC driver that came with DB2 client 8.1 does behave weirdly when it's connected to the UDB2 server 7.2.5. Although getting the column count seems to work, attempting to get the primary keys for a table will result in a The stored proc is not supported in the current version. I suspect the problem comes about because the JCC driver uses some calls that are not found in earlier versions of UDB2 server.

    Attempting to use the net driver however, will either, cause the Java application to just get stuck trying to connect or, throw out a CLI0621E: Unsupported JDBC server configuration error.

    These are my latest findings. I will probe more into this issue and post my findings here. Thanks for your responses!

  6. #6
    Join Date
    Sep 2002
    Location
    Pinellas County Florida
    Posts
    20

    How to use the 8.x driver with a 7.2 db

    According to IBM, the only way to use the 8.1 driver with a 7.2 database is to apply at least fix pack 8 to the 7.2 database (last time I checked, fix pack 10 was available). Then the 7.2 database has to be converted to use DRDA protocol (rather than the previous IBM proprietary protocol) using the db2updv7 utility.

    In an IBM document titled "Client/Server Compatibility and Migration Considerations, Version 8", on page 10 (page 16 of the PDF file) look at Table 1. "DB2 Version 7 and Version 8 client/server matrix". This shows that a v8 client can access a 7.2 client, but there are two footnotes (numbered 1 & 7).

    1. DB2 UDB Version 7 server must be configured as a DRDA™ application server (AS)....

    7. When you have a Version 8 32-bit client working with a Version 7 32-bit server, or when you have a Version 8 64-bit client working with a Version 7 64-bit server, then DB2 Universal Database Version 7 server must be at a FixPak 8 or later level. The db2updv7 utility must be run on the server in order for it to be accessible from a DB2 Universal Database Version 8 client. Once this utility is run on a database, this database cannot be used with an instance that is at an earlier FixPak level.
    It's available online here: http://www.db2.jp/db2manual/en_US/in...t/r0009731.htm

    BTW, have you ever noticed how hopeless it is to search for a document on the IBM website? Here I knew the name of a document, but when I searched for it by name and specified that I wanted to restrict the search to Database documents, I still got a list of nearly 100,000 items and the document with the title I gave them was not in the first 20 hits!

    Thank goodness for google... (and thank goodness the English version of this document was posted on the IBM Japan website).

  7. #7
    Join Date
    Sep 2002
    Location
    Pinellas County Florida
    Posts
    20

    After converting to DRDA

    It goes without saying that, after converting to DRDA, the database will not be accessible to non-DRDA clients.

  8. #8
    Join Date
    Aug 2003
    Posts
    11

    Re: How to use the 8.x driver with a 7.2 db

    [SIZE=1]Originally posted by milkchaser
    According to IBM, the only way to use the 8.1 driver with a 7.2 database is to apply at least fix pack 8 to the 7.2 database (last time I checked, fix pack 10 was available). Then the 7.2 database has to be converted to use DRDA protocol (rather than the previous IBM proprietary protocol) using the db2updv7 utility.
    Does this mean that we are able to use the DB2 8.1 Class 4 (com.ibm.db2.jcc.DB2Driver) driver for Java? Or do we have to use the class 2 and 3 JDBC drivers?

    Thanks for your help!

  9. #9
    Join Date
    Sep 2002
    Location
    Pinellas County Florida
    Posts
    20

    Re: How to use the 8.x driver with a 7.2 db

    Originally posted by A340-313X
    Does this mean that we are able to use the DB2 8.1 Class 4 (com.ibm.db2.jcc.DB2Driver) driver for Java? Or do we have to use the class 2 and 3 JDBC drivers?

    Thanks for your help!
    Disclaimer: I have not tried this, I'm just reporting what I've been told.

    The 8.1 db2java.zip contains the Type 2 & 3 drivers, if I'm not mistaken. I was led to believe that there's no advantage to using them, other than that they will allow existing code to continue working.

    However, yes, this process should make a 7.2 DB accessible via the 8.1 Type 4 all-Java driver as well (com.ibm.db2.jcc.DB2Driver).

    ..Bob.

  10. #10
    Join Date
    May 2003
    Posts
    27

    1. DB2 UDB Version 7 server must be configured as a DRDA?application server (AS)....

    Quote:
    ------------------------------------------------------------------------------------
    1. DB2 UDB Version 7 server must be configured as a DRDA?application server (AS)....
    ------------------------------------------------------------------------------------

    What should I do to enable DRDA on the DB2 Server??
    which client is non-DRDA clients??

  11. #11
    Join Date
    Sep 2002
    Location
    Pinellas County Florida
    Posts
    20
    What should I do to enable DRDA on the DB2 Server??

    The db2updv7 utility must be run on the [remote DB2] server in order for it to be accessible from a DB2 Universal Database Version 8 client.

    See http://www.db2.jp/db2manual/en_US/i...rt/r0009731.htm for details.

    which client is non-DRDA clients??

    Version 8 DB2 clients use the DRDA protocol (an industry standard). Previous clients do not.

  12. #12
    Join Date
    Aug 2006
    Posts
    1

    Alternative solution....

    Quote Originally Posted by A340-313X
    Hello

    I am trying to use the JDBC driver provided by IBM for DB2 to connect to a remote server. I am using Jbuilder 7 to write the application. However, it seems that the application just keeps trying to connect for a very long time but with no response.

    Here's a part of the code:
    ------------------------------
    try{
    Class.forName("COM.ibm.db2.jdbc.net.DB2Driver").ne wInstance();
    Connection con = DriverManager.getConnection("jdbc:db2://host/dbname", "db2user", "db2pwd");
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("QUERYSTATEMENT");
    System.out.println(rs.getMetaData().getColumnCount ());
    con.close();
    }
    catch (Exception ex) {
    ex.printStackTrace();
    }
    ------------------------------

    It hangs at the line Connection con = DriverManager.getConnection(...);.

    The remote server is running on DB2 v7.2.

    Does anyone have a clue as to what is happening? I would greatly appreciate any help I can get. Thanks!

    Hi!

    If anyone ever runs into this situation where the getConnection() hangs with jcc driver, it's worth checking that you have both the db2jcc.jar and db2_licence_cu.jar on your classpath. That did the trick for me. Cheers

    Btw. jcc driver works fine with older versions of db2 too (< 8.1)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •