java 如何从 64 位 JVM 连接到 32 位 Access 数据库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10289655/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 00:24:34  来源:igfitidea点击:

How to connect to a 32-bit Access Database from 64-bit JVM?

javams-access32bit-64bitjdbc-odbc

提问by Pedro

So far, when I had to connect to an 32-bit Access Database, I simply executed the application using 32-bit JVM. However, I am now developing an application that requires 64-bit JVM, but I still need to connect to an 32-bit Access Database. When I am trying connect, I get this exception:

到目前为止,当我必须连接到 32 位 Access 数据库时,我只是使用 32 位 JVM 执行应用程序。但是,我现在正在开发一个需要 64 位 JVM 的应用程序,但我仍然需要连接到 32 位 Access 数据库。当我尝试连接时,出现此异常:

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)

This is my code:

这是我的代码:

String s = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + path;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection(s, user, password);

回答by Bruce Martin

From my experience

根据我的经验

For User (or System ?) ODBC DSN's there are seperate 32 bit and 64 bit definitions. I think you probably have a 32 bit definition, but Java ODBC-Bridge is looking for the 64 bit definition. You can not directly connect to a 32 bit Access ODBC driver from a 64 bit program (you get an error saying this if you try).

对于用户(或系统?)ODBC DSN,有单独的 32 位和 64 位定义。我认为您可能有 32 位定义,但 Java ODBC-Bridge 正在寻找 64 位定义。您无法从 64 位程序直接连接到 32 位 Access ODBC 驱动程序(如果您尝试,则会收到错误提示)。

While Microsoft distributes 32 bit ODBC Microsoft Access Drivers with Windows (32 & 64 bit), it does not distribute 64 bit MsAccess drivers with Windows 64. There is a a 64 bit Access ODBC Driveravailable from Microsoft. There are some issues with downloading and installing the 64 bit MsAccess driver

虽然 Microsoft 随 Windows(32 位和 64 位)分发 32 位 ODBC Microsoft Access 驱动程序,但它不会随 Windows 64 分发 64 位 MsAccess 驱动程序。Microsoft 提供了64 位 Access ODBC 驱动程序。下载和安装 64 位 MsAccess 驱动程序存在一些问题

  • The Java / Driver only worked intermittently when I tested it with Java 6 (64 bit); I have not tested it with Java 7. With java 6, I think you may be OK if String fields are at the end of SQL select statments. I found some SQL statements worked some did not.
  • with the 32 bit driver, you know exactly where there driver is located, with 64 bit driver you do not know where it will be installed. This makes automated installation scripts difficult to write.
  • You will also need to create separate 64 bit ODBC definitions.

    ===============================================

  • 当我用 Java 6(64 位)测试它时,Java / 驱动程序只能间歇性地工作;我还没有用 Java 7 测试过它。对于 Java 6,我认为如果 String 字段位于 SQL select 语句的末尾,你可能没问题。我发现一些 SQL 语句起作用了一些没有。
  • 使用 32 位驱动程序,您确切知道驱动程序所在的位置,使用 64 位驱动程序,您不知道它将安装在哪里。这使得自动安装脚本难以编写。
  • 您还需要创建单独的 64 位 ODBC 定义。

    ================================================

On a different note, It may be possible to run a some Database Proxy/Pooling package running in a 32 bit java (and connect via TCP/IP ?). I have Never tried it though.

另一方面,可以运行一些在 32 位 java 中运行的数据库代理/池包(并通过 TCP/IP 连接?)。我从来没有尝试过。

Java 64 -->> DB Proxy running 32 bit Java DB -->> Ms Access

Java 64 -->> 运行 32 位 Java DB 的 DB 代理 -->> Ms Access

Database Proxy List: http://www.manageability.org/blog/stuff/jdbc-proxy-drivers

数据库代理列表:http: //www.manageability.org/blog/stuff/jdbc-proxy-drivers

something like SSL-SQL-Proxy Server may work

像 SSL-SQL-Proxy Server 这样的东西可能会工作

Good luck, hopefully some one can provide you with a solution

祝你好运,希望有人可以为您提供解决方案



Since the original answer, there are 2 JDBC driver's

自原始答案以来,有 2 个 JDBC 驱动程序的

Open Source:http://ucanaccess.sourceforge.net/site.html

开源:http : //ucanaccess.sourceforge.net/site.html

Commercial:http://www.csv-jdbc.com/stels_mdb_jdbc.htm

商业:http : //www.csv-jdbc.com/stels_mdb_jdbc.htm

I have not tried either

我也没试过



Edit: 8th May 2014

编辑:2014 年 5 月 8 日

Looks to be more commercial drivers Easysoft Driverand HXTT Driver

看起来比较商业化的驱动 Easysoft DriverHXTT Driver

This Articlemay be useful

这篇文章可能有用



Edit 6 Jan 2016

2016 年 1 月 6 日编辑

As Gord Thompson says; the ODBC-Bridge has been removed from Java 8. The good news is UCanAccessis being actively developed and they seem to making steady progress.

正如戈德汤普森所说;ODBC-Bridge 已从 Java 8 中删除。好消息是UCanAccess正在积极开发中,并且它们似乎取得了稳步进展。

回答by Gord Thompson

Now that the JDBC-ODBC Bridge has been removed from Java 8 all of these issues surrounding Access ODBC will increasingly become a thing of the past and a "real" JDBC driver will be required.

既然 JDBC-ODBC 桥已经从 Java 8 中删除,所有这些围绕 Access ODBC 的问题将越来越成为过去,并且需要一个“真正的”JDBC 驱动程序。

As mentioned in an earlier answer, UCanAccessis a free open-source option. It is a pure Java implementation that does not use ODBC at all, so it will work regardless of the platform (Windows, Linux, ...) or architecture (32-bit or 64-bit).

正如之前的回答中提到的,UCanAccess是一个免费的开源选项。它是一种完全不使用 ODBC 的纯 Java 实现,因此无论平台(Windows、Linux 等)或体系结构(32 位或 64 位)如何,它都可以工作。

For more information on using UCanAccess, see the related question here.

有关使用 UCanAccess 的更多信息,请参阅此处的相关问题。

回答by Ahmed Salem

The problem is that you should run on Java 32 bit try to install latest JDK and it will work

问题是您应该在 Java 32 位上运行尝试安装最新的 JDK,它会起作用

I run it using JDK version "jdk-7u67-windows-i586.exe"

我使用 JDK 版本“jdk-7u67-windows-i586.exe”运行它