Java 64 位 Windows 中到 Access 数据库的 ODBC 连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18751308/
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
ODBC connection to Access database in 64-bit Windows
提问by CodeMed
I am using this tutorialto create a database connection from a java application to a Microsoft Access 2010 database. The tutorial creates a system dsn in windows, and then connects to that system dsn using the following line of java code:
我正在使用本教程创建从 Java 应用程序到 Microsoft Access 2010 数据库的数据库连接。本教程在 Windows 中创建一个系统 dsn,然后使用以下 Java 代码行连接到该系统 dsn:
Connection conn = DriverManager.getConnection("jdbc:odbc:DSN_NAME");
The problem is that, when I click the link to add a new system dsn at:
问题是,当我单击链接以在以下位置添加新系统 dsn 时:
Control Panel --> System and Security --> Administrative Tools --> Data Sources (ODBC) --> (System DSN Tab) --> (Add.. button)
It does not give me an option to choose Microsoft Access as the database type. Instead, the options given are shown in the following printscreen:
它没有给我选择 Microsoft Access 作为数据库类型的选项。相反,给出的选项显示在以下打印屏幕中:
I am wondering if this is a driver issue, where I need to download something. Or if it is a configuration issue. I am using Windows 7. Can anyone show me how to fix this so that I can create the System dsn required to complete this tutorial? Or at least show me another easy way to connect to a Microsoft Access database from java?
我想知道这是否是驱动程序问题,我需要在哪里下载一些东西。或者是配置问题。我使用的是 Windows 7。谁能告诉我如何解决这个问题,以便我可以创建完成本教程所需的系统 dsn?或者至少告诉我另一种从 Java 连接到 Microsoft Access 数据库的简单方法?
采纳答案by Gord Thompson
64-bit Windows machines have two separate "ODBC Data Source Administrator" control panels: one that creates 64-bit DSNs for 64-bit applications, and a separate one that creates 32-bit DSNs for 32-bit applications. On a 64-bit Windows machine,
64 位 Windows 机器有两个独立的“ODBC 数据源管理器”控制面板:一个为 64 位应用程序创建 64 位 DSN,另一个为 32 位应用程序创建 32 位 DSN。在 64 位 Windows 机器上,
Control Panel > Administrative Tools > Data Sources (ODBC)
控制面板 > 管理工具 > 数据源 (ODBC)
will open the 64-bit ODBC Data Source Administrator. To open the 32-bit counterpart you need to run
将打开 64 位 ODBC 数据源管理器。要打开 32 位副本,您需要运行
C:\Windows\SysWOW64\odbcad32.exe
C:\Windows\SysWOW64\odbcad32.exe
You don't see an Access database driver because you are running a 64-bit version of Windows and there is no 64-bit Access driver included with Windows. Windows doesship with a 32-bit Jet driver (.mdb files only).
您看不到 Access 数据库驱动程序,因为您运行的是 64 位版本的 Windows,并且 Windows 中没有包含 64 位 Access 驱动程序。窗户不附带32位驱动程序的Jet(.MDB仅文件)。
So, you will need to do one of the following:
因此,您需要执行以下操作之一:
If you are running a 32-bit version of Java and you want to connect to an
.mdb
file then you need to launch the 32-bit ODBC Data Source Administrator as described above.If you are running a 32-bit version of Java and you want to be able to connect to both
.accdb
and.mdb
files then you need to download and install the 32-bit version of the Access Database Engine from hereand then launch the 32-bit ODBC Data Source Administrator as described above.If you are running a 64-bit version of Java then you need to download and install the 64-bit version of the Access Database Engine from here.