JDBC-ODBC、无 DSN 连接字符串和 64 位 Windows 7 的问题
我正在处理一个应用程序出现的问题,该应用程序通过 JDBC-ODBC 连接到 Access 文件。在其他 Windows 平台上,尚未遇到此问题,但在 Windows 7 64 位机器上,尝试使用无 DSN 连接字符串进行连接时会返回:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
已尝试对字符串进行多种变体,但所有变体都返回相同的结果错误。以下是它当前尝试连接的方式:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
StringBuffer databaseConnectionString;
if (SystemUtils.IS_OS_WINDOWS_7) {
databaseConnectionString = new StringBuffer("jdbc:odbc:DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=");
databaseConnectionString.append(databaseFile);
} else {
databaseConnectionString = new StringBuffer("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=");
databaseConnectionString.append(databaseFile);
databaseConnectionString.append(";DriverID=22;READONLY=false}");
}
在 32 位 ODBC 数据源管理器中检查驱动程序,确认驱动程序是否存在。但是,当使用 regedt32.exe 检查 ODBC 驱动程序(HKEY_LOCAL_MACHINE/SOFTWARE/ODBC/ODBCINST.INI/ODBC Drivers)
时,它们都不会出现。
任何人都可以帮助阐明这一点吗?
I'm dealing with an issue that has arisen for an application I've been working on which connects to a Access file via JDBC-ODBC. On other Windows platforms, this issue hasn't been encountered, but on Windows 7 64-bit boxes, attempting to connect with DSN-less connection strings return:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Multiple variations on the string have been attempted, but all of them have returned the same error. Here's how it currently tries to connect:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
StringBuffer databaseConnectionString;
if (SystemUtils.IS_OS_WINDOWS_7) {
databaseConnectionString = new StringBuffer("jdbc:odbc:DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=");
databaseConnectionString.append(databaseFile);
} else {
databaseConnectionString = new StringBuffer("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=");
databaseConnectionString.append(databaseFile);
databaseConnectionString.append(";DriverID=22;READONLY=false}");
}
Examining the driver in the 32-bit ODBC Data Source Admin confirms that the drivers are present. However, when regedt32.exe is used to examine ODBC drivers (HKEY_LOCAL_MACHINE/SOFTWARE/ODBC/ODBCINST.INI/ODBC Drivers)
, none of them appear.
Can anyone help to shed some light on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现问题是我在 64 位 Java 中运行该程序。 我已经通过安装 32 位 Java 运行时环境并使用如下所示的 .bat 文件解决了该解决方案:
虽然我还没有成功让程序检测它是在 32 位还是 64 位 Java 中运行,但 帮助!
I found the problem was that I was running the program in 64-bit Java. Although I have yet to successfully have the program detect if it's running in 32-bit or 64-bit Java, I have solved the solution by installing a 32-bit Java runtime environment and using a .bat file that reads as follows:
Thanks for the help!
由于 JAVA 或 MS 的 ODBC 驱动程序缺乏有意义的错误消息,这是一个艰巨的挑战。上面关于选择 32 位 Java 和 MS Access 驱动程序(使用 MS 的 AccessDatabaseEngine.exe)的答案确实有效,但与使用 64 位 Java 相比,在处理其他操作时成本高昂(约 30%)。我不愿意支付这个价格,所以我安装了 64 位 Java(与 32 位一起,都在单独的目录 c:\Java\32 或 64 中)。后一个目录问题对我来说很重要,因为我使用的是 Apache Geronimo,并且如果 Java 安装在 Program Files (x86) 中,它就不会启动...因为 (x86) 似乎会终止其批处理文件解析。然后我卸载了 32 位 MS Access 并安装了 64 位 MS Access (AccessDatabaseEngine_x64.exe)。最后,它可以支持更高的速度和 MDB 连接。
This was a difficult challenge given the paucity of meaningful error messages from JAVA or MS's ODBC driver. The answers above about down selecting to 32bit Java and MS Access drivers (using AccessDatabaseEngine.exe from MS) did work but cost a significant penalty (about 30%) in processing other actions compared to using 64bit Java. I was unwilling to pay this price so I installed 64bit Java (in conjunction with 32bit, both in a separate directory c:\Java\32 or 64). This latter directory issue was important for me since I was using Apache Geronimo and it would not start if Java was installed in Program Files (x86)... as the (x86) seemed to kill its batch file parsing. I then uninstalled 32bit MS Access and installed 64bit MS Access (AccessDatabaseEngine_x64.exe). Finally, it worked with both higher speed and MDB connection.