【问题标题】:Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:ucanaccess://C:/Users/gfas1/Desktop/st.accdb线程“主”java.sql.SQLException 中的异常:找不到适合 jdbc:ucanaccess://C:/Users/gfas1/Desktop/st.accdb 的驱动程序
【发布时间】:2019-10-17 20:26:13
【问题描述】:

所以我试图在 access 数据库中建立连接,但否则失败。 我已经导入了 ucanaccess 5 个文件,我很困惑为什么这不起作用。 Here are the jars

public class Access {

public static void main(String[] args) throws ClassNotFoundException, SQLException {
    // TODO Auto-generated method stub


        Connection conn=DriverManager.getConnection("jdbc:ucanaccess://C:/Users/gfas1/Desktop/st.accdb");
        Statement stment = conn.createStatement();
        String qry = "SELECT * FROM Students";

        ResultSet rs = stment.executeQuery(qry);
        while(rs.next())
        {
            String id    = rs.getString("ID") ;
            String fname = rs.getString("Name");

            System.out.println(id + fname);
        }
    }



} 

【问题讨论】:

  • 您应该尝试在您的开发环境中“通过选择选项添加为库”将 jar 文件添加到类路径中,仅将 jar 文件放在您的项目中将不会帮助您.这里以更好的方式描述了许多选项stackoverflow.com/questions/3193849/…

标签: java ms-access connection


【解决方案1】:

应该加载 JDBC 驱动程序,并且你的类路径中应该有驱动程序 jar

Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");

在这种情况下,驱动程序会自行注册,Java 知道如何处理这些数据库连接。

另见http://ucanaccess.sourceforge.net/site.html

【讨论】:

  • 如何找到 com.your?你是说哪个司机?
  • 我为您更新了包裹。只需在 DriverManager.getConnection() 调用之前添加它
  • 但是所有的教程都说在这个java版本中,不需要class.forName这行
  • 线程“主”java.lang.ClassNotFoundException 中的异常:net.ucanaccess.jdbc.UcanaccessDriver
  • 您必须将ucanaccess jar添加到类路径并调用Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");在您尝试打开连接之前。见ucanaccess.sourceforge.net/site.html
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-22
  • 2015-07-09
  • 2013-07-04
  • 1970-01-01
  • 2016-11-28
  • 2011-08-02
相关资源
最近更新 更多