如何从64位Java连接到Access .mdb数据库? [英] How to connect to Access .mdb database from 64-bit Java?

查看:183
本文介绍了如何从64位Java连接到Access .mdb数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有以下代码连接到Windows 7操作系统上的MS Access数据库。我已将数据源快捷方式更改为指向64位odbc然后32位。但仍然得到错误

Hi I have the below code to connect to MS Access database on Windows 7 OS. I have changed the Data Source short cut to point to 64bit odbc then 32 bit. But still getting the error as

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6956)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7113)
    at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3072)
    at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
    at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
    at java.sql.DriverManager.getConnection(DriverManager.java:579)
    at java.sql.DriverManager.getConnection(DriverManager.java:221)
    at TestDBConnection.main(TestDBConnection.java:21)

我的代码是:

import java.sql.Connection;
import java.sql.DriverManager;

public class TestDBConnection {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try
        {
            System.out.println("filename");
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String database = 
                      "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\\Test\\Tests.mdb";
            Connection conn = DriverManager.getConnection(database, "", "");
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }

}

如何我有SQL Workbench工具,我可以通过它连接到它但不通过Java代码。

How ever I have SQL Workbench tool through which I can connect to it but not through java code.

由于我在过去3个小时内在谷歌搜索时遇到困难,所以请急需帮助。

Please need help badly as I am struggling with this from past 3 hours searching on Google.

推荐答案

如果您的Java应用程序在64位Java虚拟机(JVM)中运行,那么 DRIVER = {Microsoft Access Driver(* .mdb)} 因为没有64位版本的Jet数据库引擎而无法工作。您可以...

If your Java app is running in a 64-bit Java Virtual Machine (JVM) then DRIVER={Microsoft Access Driver (*.mdb)} is not going to work because there is no 64-bit version of the Jet database engine. You can...


  • 此处,然后使用 DRIVER = {Microsoft Access Driver(代码中有* .mdb,* .accdb)}

  • Download and install the 64-bit version of the Microsoft Access Database Engine from here, and then use DRIVER={Microsoft Access Driver (*.mdb, *.accdb)} in your code.

...或...


  • 在32位JVM中运行Java应用程序并继续使用现有的 DRIVER = 字符串。如果您选择此选项,此处的相关答案可能会有所帮助。

  • Run your Java app in a 32-bit JVM and continue to use the existing DRIVER= string. The related answer here might prove helpful if you choose this option.

...或...


  • 使用 UCanAccess Access数据库的JDBC驱动程序。它是一个免费的,开源的纯Java实现,因此它适用于32位和64位系统,包括Windows和非Windows。它也适用于Java 8(已经删除了JDBC-ODBC Bridge)。有关详细信息,请参阅:

  • Use the UCanAccess JDBC driver for Access databases. It is a free, open-source, pure Java implementation so it works on both 32-bit and 64-bit systems, both Windows and non-Windows. It also works with Java 8 (which has dropped the JDBC-ODBC Bridge). For more details, see:

         在没有ODBC的情况下从Java操作Access数据库

        Manipulating an Access database from Java without ODBC

这篇关于如何从64位Java连接到Access .mdb数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆