Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2006
    Posts
    3

    Angry Unanswered: JDBC cant connect to DB2

    hi all!
    as the title....

    OS:windows 2000 prefessional
    DB2 version:8.2

    ----------codes----------------

    package com.servinvent.itmanager.test;

    import java.sql.*;


    public class DB2Test {
    static Connection con = null;
    static Statement stmt = null;

    static String url = "jdbc:db2AMPLE";
    //String url = "jdbc:db2://172.16.104.47:50000/sample";
    //String user = "root";
    //String password = "root";
    String user = "MAOLI";
    String password = "111111";
    DB2Test(){}


    public static void main(String[] args) {

    try{
    //DriverManager.registerDriver(new COM.ibm.db2.jdbc.app.DB2Driver());
    //Class.forName("org.gjt.mm.mysql.Driver").newInstan ce();
    //Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").ne wInstance();
    //Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").ne wInstance();
    System.out.println("register start");
    DriverManager.registerDriver(new COM.ibm.db2.jdbc.app.DB2Driver());
    //Class.forName("com.ibm.db2.jcc.DB2Driver");
    //Class.forName("com.ibm.db2.jdbc.net.DB2Driver");
    System.out.println("----");
    }catch(Exception e){
    e.printStackTrace();
    }
    try {
    con = DriverManager.getConnection(url);
    stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("select * from T$salary");
    while (rs.next()){
    System.out.println(rs.getString(1));
    }
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }finally{
    if (con != null)
    con = null;
    }

    }
    }

    ----------Exceptions-----------
    java.sql.SQLException: java.lang.UnsatisfiedLinkError: no db2jdbc in java.library.path
    at COM.ibm.db2.jdbc.app.DB2Driver.<init>(Unknown Source)
    at com.servinvent.itmanager.test.DB2Test.main(DB2Test .java:27)
    java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getConnection(DriverManager .java:532)
    at java.sql.DriverManager.getConnection(DriverManager .java:193)
    at com.servinvent.itmanager.test.DB2Test.main(DB2Test .java:35)

    ----------Environment--------
    CLASSPATH:

    .;D:\PROGRA~1\IBM\SQLLIB\java\db2java.zip;D:\PROGR A~1\IBM\SQLLIB\java\db2jcc.jar;D:\PROGRA~1\IBM\SQL LIB\java\sqlj.zip;D:\PROGRA~1\IBM\SQLLIB\java\db2j cc_license_cisuz.jar;D:\PROGRA~1\IBM\SQLLIB\java\d b2jcc_license_cu.jar;D:\PROGRA~1\IBM\SQLLIB\bin;D: \PROGRA~1\IBM\SQLLIB\java\common.jar

    Path:

    C:\ITManager\jdk-windows\bin;C:\ITManager\jdk-windows\jre\bin\client;C:\ITManager\bin;C:\WINNT\; C:\WINNT\system32;%SystemRoot%\system32;%SystemRoo t%;%SystemRoot%\System32\Wbem;D:\Program Files\Rational\ClearCase\bin;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;D:\PROGRA~1\IBM\SQLLIB\BIN;D: \PROGRA~1\IBM\SQLLIB\FUNCTION;D:\PROGRA~1\IBM\SQLL IB\SAMPLES\REPL

    --------------------------------------------------------------------
    Thanks!!!!

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    I am not sure what your problem is. It looks like you have tried a myriad of things. This is what works for me using the Type 4 driver:


    Class.forName("com.ibm.db2.jcc.DB2Driver").newInst ance();
    url = new String("jdbc:db2://" + server + ":" + port + "/" + serverDB);

    java.sql.Connection c = java.sql.DriverManager.getConnection(url,username, passwd);


    Andy

  3. #3
    Join Date
    Dec 2006
    Posts
    3
    thanks andy

    i've killed the problem.
    it must use IBM's JDK and the "db2jdbc.dll" should be at the root.library.path

Posting Permissions

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