我正在 Eclipse EE IDE 中的 Java 项目中工作,我必须在其中查询.accdb
文件。
问题是当我尝试加载驱动程序然后连接到数据库时,它给了我一个异常错误。
My code:
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
}
例外情况:
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)
我在 64 位 Windows 中使用 32 位 Eclipse,根据我的阅读,64 位 JRE 不支持这种连接数据库的方式,因此我使用选定的 32 位 JRE ( jdk1.8.0_05),在我的运行配置中,我在虚拟机中使用了“-d32”参数。
显然是JdbcOdbcDriver
应该在里面rt.jar,但是当我寻找它时,我找不到以下包:sun.jdbc.odbc.JdbcOdbcDriver
.
如果有人能阐明我的问题,我将不胜感激,我所说的任何错误或愚蠢的事情也可以随时纠正我。
根据this https://blogs.oracle.com/Lance/entry/removal_of_the_jdbc_odbc在 Java8 中删除了 JDBC-ODBC 桥之后。您可以使用专门用于 Access 的 JDBC 驱动程序。我看到很多人提到UCanAccess http://ucanaccess.sourceforge.net/site.html连接到 Access 虽然我自己没有使用过它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)