小编Vit*_*itz的帖子

尝试通过Java 8中的JDBC-ODBC连接到.accdb文件时出现ClassNotFoundException

我正在Eclipse EE IDE中的Java项目中工作,我必须查询.accdb文件.问题是当我尝试加载驱动程序然后连接到数据库时,它给我一个异常错误.

我的代码:

try{
        String filePath = "//myfilepathtomydb/BLABLA/example.accdb"

        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

        String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + filePath;

        Connection database = DriverManager.getConnection(url);

        System.out.println("Connection sucessful");

    } catch (ClassNotFoundException e){     
        System.err.println("Got an exception");
        System.err.println(e.getMessage());
        e.printStackTrace();
    } catch (SQLException sqle) {
        sqle.printStackTrace();
        // TODO: handle exception
    }
Run Code Online (Sandbox Code Playgroud)

例外:

Got an exception
sun.jdbc.odbc.JdbcOdbcDriver
java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:259)
    at project.Main.main(Main.java:15)
Run Code Online (Sandbox Code Playgroud)

我在64位Windows中使用32位Eclipse,并且从我读过的这种连接到数据库的方式不支持64位JRE,所以我使用的是选择的32位JRE( jdk1.8.0_05)在我的运行配置中,我在VM中使用了'-d32'参数.

显然 …

java eclipse ms-access-2010 jdbc-odbc java-8

3
推荐指数
1
解决办法
5954
查看次数

标签 统计

eclipse ×1

java ×1

java-8 ×1

jdbc-odbc ×1

ms-access-2010 ×1