1

我刚刚安装了 DB2 Express-C 版本 10.1(最新的),并尝试连接到 SAMPLE 数据库。我已经通过db2.exe完成了,一切正常。这是我的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

0 回答 0