DB2 java连接驱动程序

时间:2013-02-11 23:44:28

标签: java db2

我刚刚安装了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与驱动程序添加到我的库中,以便找到它。 也许我有一些错误的设置?

0 个答案:

没有答案