视窗 8.1。- Java - ODBC 驱动程序 - NetBeans

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

Windows 8.1. - Java - ODBC Driver - NetBeans

javawindows-8.1jdbc-odbcnetbeans-8

提问by j3ca

I am trying to connect Java app to MSAccess in NetBeans IDE (pls don't tell me not to use Access, because we are using it in classes, and that's just it for now :)). I didn't have this problem on Windows 7, and I couldn't find answer using Google, so I decided to post this question. So, it's like this, I have:

我正在尝试将 Java 应用程序连接到 NetBeans IDE 中的 MSAccess(请不要告诉我不要使用 Access,因为我们在类中使用它,现在就这样:))。我在 Windows 7 上没有这个问题,我无法使用谷歌找到答案,所以我决定发布这个问题。所以,就像这样,我有:

  • Windows 8.1 (64-bit)
  • Java jdk1.8.0 (32-bit)
  • NetBeans IDE 8.0, and NetBeans jdk home (from netbeans.conf) is: "C:\Program Files (x86)\Java\jdk1.8.0", so it's using 32-bit jdk.
  • Windows 8.1(64 位)
  • Java jdk1.8.0(32位)
  • NetBeans IDE 8.0 和 NetBeans jdk home(来自 netbeans.conf)是:“C:\Program Files (x86)\Java\jdk1.8.0”,所以它使用 32 位 jdk。

Code for loading driver:

加载驱动代码:

public void loadDriver() throws RuntimeException {
    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    } catch (Exception e) {
        throw new RuntimeException("Could not load driver!");
    }
}

Code for opening connection:

打开连接的代码:

public void openConnection() throws RuntimeException {
    try {
        connection = DriverManager.getConnection("jdbc:odbc:db");
        connection.setAutoCommit(false);
    } catch (Exception e) {
        throw new RuntimeException("Could not connect!");
    }
}

Of course, there's an attribute: private Connection connection; (and import java.sql.Connection;)

当然还有一个属性:private Connection connection;(并导入 java.sql.Connection;)

There is a problem at loading driver - it always says "could not load driver". If I have to post more code or change something in what I've posted, please tell me and I will.

加载驱动程序时出现问题 -它总是说“无法加载驱动程序”。如果我必须发布更多代码或更改我发布的内容,请告诉我,我会的。

I went to: SysWOW64 - odbcad32.exe - Add... - Microsoft Access Driver (*.mdb, *.accdb), and then for Data source name I've put of course "db" (like in my code above) and selected the database (.accdb file) that I will use. And I don't know if it is the Windows 8 issue or I'm forgetting something, but I really have no clue how to make it work.

我去了:SysWOW64 - odbcad32.exe - Add... - Microsoft Access Driver (*.mdb, *.accdb),然后对于数据源名称,我当然已经把“db”(就像我上面的代码一样)并选择了我将使用的数据库(.accdb 文件)。我不知道是 Windows 8 的问题还是我忘记了什么,但我真的不知道如何让它工作。

采纳答案by Gord Thompson

The JDBC-ODBC Bridge has been removed from Java 8. For an alternative, see the related question here:

JDBC-ODBC Bridge 已从 Java 8 中删除。有关替代方案,请参阅此处的相关问题:

Manipulating an Access database from Java without ODBC

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