0

从 Java 中,我想连接到服务器中的 .ACCDB 文件(DSN 较少)并且我不断收到错误消息。我用谷歌搜索了几个小时,找不到任何东西。请帮忙!

String sURL = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=DBQ=C:/test/theDB.accdb;READONLY=true;";

        try {   
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");          
            log.debug("url: "+sURL);                

            // create connection to database using connection string
            dbCon = DriverManager.getConnection(sURL);

}
catch(SQLException e) {
            //retry
            try{dbCon = DriverManager.getConnection(sURL);}
            catch(SQLException ex){
                // Now, it is real failing. Throw exception
                log.error("Fail second time",ex);
                throw new SQLException(e.getMessage());
            }
        } catch (ClassNotFoundException e) {
            log.error(e.getMessage());
            throw new SQLException(e.getMessage());
        } 
        return dbCon;

这是我得到的例外:

java.sql.SQLException:[Microsoft][ODBC Driver Manager] 未找到数据源名称,并且未在 sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source) [na:1.7.0_10] 在 sun.jdbc 中指定默认驱动程序。 odbc.JdbcOdbc.standardError(Unknown Source) [na:1.7.0_10] at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source) [na:1.7.0_10] at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source ) [na:1.7.0_10] at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source) [na:1.7.0_10] at java.sql.DriverManager.getConnection(Unknown Source) [na:1.7.0_10] at java .sql.DriverManager.getCon...

4

1 回答 1

0

DBQ=DBQ=C: ...可能会导致问题。一个DBQ=就足够了。

于 2013-05-13T17:44:23.467 回答