eclipse - 为什么我的代码不断收到 java.sql.SQLException : [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified?

标签 eclipse ms-access jdbc-odbc

有人可以帮我让我的数据库连接到java。
我已经尝试了几个小时,但我仍然遇到此异常:“java.sql.SQLException:[Microsoft][ODBC 驱动程序管理器] 未找到数据源名称且未指定默认驱动程序?”

public Connector() {
      Connection con;
      Statement st;
    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        con = DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=Database.mdb");
        st = con.createStatement(1004, 1008);
    } catch (Exception e) 
        e.printStackTrace();
    }

} 

这是我得到的异常(exception):
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)

最佳答案

您的 Java 代码在 64 位 JVM(Java 虚拟机)下运行并尝试使用较旧的“Jet”ODBC 驱动程序 Microsoft Access Driver (*.mdb) .这是行不通的,因为旧的“Jet”驱动程序仅适用于 32 位应用程序。你要么需要

  • 在 32 位 JVM 下运行您的 Java 程序,或
  • here 下载并安装较新的“Access Database Engine ('ACE')”的 64 位版本然后使用 ODBC 驱动程序名称 Microsoft Access Driver (*.mdb, *.accdb)在 64 位 JVM 下运行代码时。

  • 另外,请记住 JDBC-ODBC Bridge 已从 Java 8 中删除,因此继续使用它不是很“ future 友好”。有关替代方案,请参阅

    Manipulating an Access database from Java without ODBC

    关于eclipse - 为什么我的代码不断收到 java.sql.SQLException : [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30559542/

    相关文章:

    sql - 将数据从 Access 复制到 SQL

    java - 无法获得 Oracle 连接

    java - Eclipse 项目中不必要的 JAR - 潜在问题?

    java - 在android中生成0到3之间的随机数并添加到数组列表中

    android - android log util 中的行号

    ms-access - 如何使用 Visual Basic 从字符串中删除停用词?

    sql - Access : Overflow Error with UNION but not with UNION ALL or Individual Queries

    java - Java 中的 "undefined symbol: SQLAllocEnv"错误

    java - 异常: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application "

    Eclipse - 下载 content.jar ... 安装插件时超时