DB2Java连接驱动程序

DB2Java连接驱动程序,java,db2,Java,Db2,我刚刚安装了DB2Express-C10.1版(最新版本),并尝试连接到一个示例数据库。我已经通过db2.exe完成了t,所有这些都正常完成。 这是我的java代码 String url = "jdbc:db2:SAMPLE"; String user = "db2admin"; String password = "db2admin"; Connection conn = null; try { // Load the DB2 JDBC

我刚刚安装了DB2Express-C10.1版(最新版本),并尝试连接到一个示例数据库。我已经通过db2.exe完成了t,所有这些都正常完成。 这是我的java代码

    String url = "jdbc:db2:SAMPLE";
    String user = "db2admin";
    String password = "db2admin";
    Connection conn = null;
    try {
        // Load the DB2 JDBC Type 2 Driver with DriverManager
        //Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
        //Driver d = new COM.ibm.db2.jcc.DB2Driver();
        Driver d = new COM.ibm.db2.jdbc.app.DB2Driver();
        if(!d.jdbcCompliant()) System.console().printf("jdbc driver is not ccompliant");
        //DriverManager.registerDriver(new COM.ibm.db2.jdbc.app.DB2Driver());
        DriverManager.registerDriver(d);
        if(!d.acceptsURL(url))
            throw new SQLException("url \"" + url + "\" is not accepted by jdbc driver");
        conn = DriverManager.getConnection(url, user, password);
        conn.setAutoCommit(false);

        /* do some work */
        conn.commit();
        conn.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
输出为

java.sql.SQLException: url "jdbc:db2:SAMPLE" is not accepted by jdbc driver
有什么问题? 我已经将带有驱动程序的.zip添加到我的库中,以便正确找到它。
也许我有一些错误的设置?

您是否尝试过使用驱动程序类型4,因为您使用的是最新版本的DB2,所以也值得尝试切换到最新的驱动程序。另外,当使用驱动程序类型4时,连接url的格式应为jdbc:db2://{IP}:{port}/SAMPLEjava.sql.SQLException:url“jdbc:db2://127.0.0.1:50000/SAMPLE”不被jdbc驱动程序接受问题已经解决了-我只是认为应用程序驱动程序不推荐使用。我使用了com.ibm.db2.jcc.DB2Driver()添加db2jcc.jar+licentjar+使用了您的url格式