java 无法使用 Windows-64 位连接到 MS Access DB
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13782957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can't connect to MS Access DB with Windows-64bit
提问by drowningincoffee
Possible Duplicate:
Microsoft Access and Java JDBC-ODBC Error
I had issues with creating my DB to begin with. I have a 64bit version of Windows 7 and found out the error was with Microsoft Office being 32bit. I was able to create my Access database by using the odbcad32.exe found in c:\Windows\sysWOW64\odbcad32.exe
我在创建数据库时遇到了问题。我有一个 64 位版本的 Windows 7,发现错误在于 Microsoft Office 是 32 位。我能够使用 c:\Windows\sysWOW64\odbcad32.exe 中的 odbcad32.exe 创建我的 Access 数据库
Now in my Java code I am simply trying to get connected but am running into issues again that seem to be related, and make me feel like at the most I just didn't set up the database correctly. JavaDB is the name of my data source I created in the ODBC:DSA as you can see here: http://i.imgur.com/9n19x.png
现在在我的 Java 代码中,我只是试图建立连接,但又遇到了似乎相关的问题,这让我觉得最多只是没有正确设置数据库。JavaDB 是我在 ODBC:DSA 中创建的数据源的名称,您可以在这里看到:http: //i.imgur.com/9n19x.png
I've been searching all over the internet but can't really find a solid definite answer. Could really use the help, thanks in advanced!
我一直在互联网上搜索,但无法真正找到可靠的明确答案。真的可以使用帮助,在此先感谢!
EDIT: I cleaned up my code and now my error is different. I have my physical database file in my project folder at C:\Eclipse\project1\src - I have set it up as well like I said in the ODBC to be the same.
编辑:我清理了我的代码,现在我的错误有所不同。我在 C:\Eclipse\project1\src 的项目文件夹中有我的物理数据库文件 - 我已经像我在 ODBC 中所说的那样进行了设置。
EDIT EDIT: Well, after hours and hours of research I ended up just figuring it out finally. The issues wasn't as much my code, as it was compatibility issues with Windows x64BIT and 32 bit drivers in Office. This article helped me fix it, and now it works! http://www.selikoff.net/2011/07/26/connecting-to-ms-access-file-via-jdbc-in-64-bit-java/
编辑 编辑:嗯,经过数小时的研究,我最终终于弄清楚了。问题不是我的代码,而是与 Windows x64BIT 和 Office 中的 32 位驱动程序的兼容性问题。这篇文章帮助我修复了它,现在它可以工作了!http://www.selikoff.net/2011/07/26/connecting-to-ms-access-file-via-jdbc-in-64-bit-java/
import java.sql.*;
public class DBTester {
public static void main(String[] args) throws SQLException, ClassNotFoundException {
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String fileName = "C:/Eclipse/school/bin/RegistrationDB.mdb";
String dB = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ="+fileName;
Connection connection = DriverManager.getConnection(dB,"","");
System.out.println("connected");
Statement s = connection.createStatement();
s.close();
connection.close();
} catch(Exception ex)
{
ex.printStackTrace();
}
} // end main
} // end class
回答by drowningincoffee
After much research and seeing tons of unanswered questions related to mine here and other places I stumbled upon an article with a simple fix that made my want to hit my head into my desk.
经过大量研究并在这里和其他地方看到大量与我的问题相关的未解决问题后,我偶然发现了一篇文章,其中有一个简单的修复方法,这让我想把头撞到我的桌子上。
http://www.selikoff.net/2011/07/26/connecting-to-ms-access-file-via-jdbc-in-64-bit-java/
http://www.selikoff.net/2011/07/26/connecting-to-ms-access-file-via-jdbc-in-64-bit-java/
If you have a 64bit Windows 7 machine and a 32Bit version of Access - you are going to have issues. From this guys article, I was able to uninstall my current MS Access - and -reinstall a 64 bit version. Re-added my DB sources and everything worked.
如果你有一台 64 位的 Windows 7 机器和一个 32 位版本的 Access - 你会遇到问题。从这篇文章中,我能够卸载我当前的 MS Access - 并重新安装 64 位版本。重新添加了我的数据库源,一切正常。