将 Java 8 与 Access 连接时出错:找不到合适的驱动程序

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

Error connecting Java 8 with Access: No suitable driver found

javadatabasems-access-2007ucanaccess

提问by user3000000

I want to connect Java 8 with Access but the following error occurs and I don't know how to fix it. I always get this error:

我想将 Java 8 与 Access 连接,但出现以下错误,我不知道如何解决。我总是收到这个错误:

java.sql.SQLException: No suitable driver found for jdbc:ucanaccess://C:/Users/Ghazi/workspace/java w access/login.accdb

java.sql.SQLException:找不到适合 jdbc 的驱动程序:ucanaccess://C:/Users/Ghazi/workspace/java w access/login.accdb

I added 4 libraries:

我添加了 4 个库:

  • hsqldb.jar
  • Hymancess-2.0.7.jar
  • org.apache.commons.lang-2.6-source.jar
  • org.apache.commons.loggin-1.1.1-source.jar
  • 数据库文件
  • Hymancess-2.0.7.jar
  • org.apache.commons.lang-2.6-source.jar
  • org.apache.commons.loggin-1.1.1-source.jar

This is my code

这是我的代码

import java.sql.*;
public class DbConnection {
    Connection con;
    Statement st;
    DbConnection(){
        dbconnect();
        }
    //-----------------------
    public void dbconnect(){
        try
        {
     Connection conn=DriverManager.getConnection("jdbc:ucanaccess://C:/Users/Ghazi/workspace/java w access/login.accdb");
      Statement stment = conn.createStatement();
        }
        catch(Exception err)
        {
            System.out.println(err);
        }
    }
    //--------------------------
        public static void main(String[]args){
            DbConnection ob=new DbConnection();
            }//end main
    }

回答by Gord Thompson

I added 4 libraries

我添加了 4 个库

You need five (5) libraries. You forgot to add the "ucanaccess-x.y.z.jar" file itself.

您需要五 (5) 个库。您忘记添加“ucanaccess-xyzjar”文件本身。

For detailed instructions, see

有关详细说明,请参阅

Manipulating an Access database from Java without ODBC

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

回答by FoggyDay

Try adding "Class.forName():

尝试添加“Class.forName():

   public void dbconnect(){
     try  {
        Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
        Connection conn=DriverManager.getConnection("jdbc:ucanaccess://C:/Users/Ghazi/workspace/java w access/login.accdb");
        Statement stment = conn.createStatement();
     }
     catch(Exception err) {
       System.out.println(err);
     }
   }

The basic problem is that earlier versions of Java/JDBC used ODBC to connect to MS-Access ... and the ODBC driver has been removed from Java 8.

基本问题是早期版本的 Java/JDBC 使用 ODBC 连接到 MS-Access……并且 ODBC 驱动程序已从 Java 8 中删除。

Two alternatives are to use:

两种选择是使用:

1) UCanAccess: http://ucanaccess.sourceforge.net/site.html

1) UCanAccess:http://ucanaccess.sourceforge.net/site.html

... or ...

... 或者 ...

2) Hymancess (Hymancess 2.0: New crunchy outside, same yummy filling!): http://Hymancess.sourceforge.net/

2)Hymancess(Hymancess 2.0:外面的新脆,同样美味的馅料!):http://Hymancess.sourceforge.net/

If that doesn't work:

如果这不起作用:

3) Please specify what what IDE you're using (Eclipse, etc - if applicable)

3) 请指定您使用的是什么 IDE(Eclipse 等 - 如果适用)

4) Make sure your Hymancess-2.0.7.jar is explicitly included in the CLASSPATH (how to do this depends on your IDE)

4) 确保您的 Hymancess-2.0.7.jar 明确包含在 CLASSPATH 中(如何执行此操作取决于您的 IDE)

5) Consider using a directory withoutspaces in the name

5)考虑使用名称中没有空格的目录