Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004
    Location
    USA
    Posts
    3

    Question Unanswered: Could not connect to database

    Hi all,

    I have a problem conneting to db2 database when I'm running my java program on Windows 98. I received "SQLException: Could not connect to database". But I don't have any problem if I use the Windows 2000 pro. Any suggestions and ideas could be great.

    Thank you in advance.
    Billy Lin


    I installed the DB2 clients on both machine. I have the classpath on both the Windows98 and Windows2000Pro.

    "CLASSPATH=.;C:\Program Files\SQLLIB\java\db2java.zip;C:\Program Files\SQLLIB\java\db2jcc.jar;C:\Program Files\SQLLIB\bin;C:\Program Files\SQLLIB\tools\db2XTrigger.jar;C:\Program Files\SQLLIB\java\common.jar;C:\Program Files\SQLLIB\java\db2jcc_license_cu.jar;"

    My DB2 vervion is: 8.1.4.341

    C:\>java -version
    java version "1.4.2_03"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)


    /*
    * testdb2connection.java
    *
    * Created on March 16, 2004, 10:17 AM
    */

    import java.sql.*;

    public class testdb2connection1 {

    public static void main(String[] args) {
    Connection con = null;
    try{
    Class.forName("COM.ibm.db2.jdbc.net.DB2Driver").ne wInstance();
    System.out.println("JDBC driver loaded");
    String url = "jdbc:db2://192.0.0.100/mytestDB";
    String user = "myusername";
    String password = "mypassword";
    con = DriverManager.getConnection(url, user, password);
    System.out.println("Database connection established");

    }catch(ClassNotFoundException cnfe){
    System.out.println("ClassNotFoundException: Could not locate driver");

    }catch(SQLException cnfe){
    System.out.println("SQLException: Could not connect to database");
    }catch(Exception e){
    System.out.println("An unknown error occurred while connecting to database");
    }finally{
    try{
    if (con != null){
    con.close();
    }
    }catch(SQLException sqle){
    System.out.println("Unable to close database connection.");
    }

    }

    }

    }

  2. #2
    Join Date
    Jan 2002
    Location
    USA
    Posts
    53
    More detail error message.

    Do you try configuration assistant?


    Ljrong

  3. #3
    Join Date
    Mar 2004
    Location
    USA
    Posts
    3
    I fixed the problem by using a new Universal JDBC Type 4 driver. Now it works fine on my Windows 98 and Windows 2000

    My new driver code is:

    Class.forName("com.ibm.db2.jcc.DB2Driver").newInst ance(); //type 4 JDBC Uiversal driver

    My old driver code was:

    //Class.forName("COM.ibm.db2.jdbc.net.DB2Driver").ne wInstance(); //type 3 JDBC for Verion 8


    Check this out:

    http://www-106.ibm.com/developerwork...ikopoulos.html

Posting Permissions

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