使用UCanAccess将Java与MS Access连接时出错。发生ClassNotFoundException

时间:2015-11-01 04:38:02

标签: jdbc ms-access-2007 ucanaccess

我想将Java 1.8与Access连接,但是发生了错误,我不知道如何修复它。 我写了这段代码:

import java.sql.*;
class db1
{
    public static void main(String args[])
    {
        //Load a driver
        try
        {
            String url = "jdbc:odbc:sample1";
            Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
            Connection con = DriverManager.getConnection("jdbc:ucanaccess://F:\\java\\project\\samp.accdb");
            //Connection con = DriverManager.getConnection("Jdbc:Odbc:sample1");
            Statement st = con.createStatement();
            String Sql = "Select * from tbsamp";
            ResultSet rs = st.executeQuery(Sql);
            //ResultSet rt = st.executeQuery(Sql);
            while (rs.next())
            {
                System.out.println(rs.getString("movie") + " \t " + rs.getString("price") + "\n");
            }
            rs.close();
            //rt.close();
            st.close();
            con.close();
        }
        catch(Exception e)
        {
            System.out.println("error " + e);
        }
    }
}

并且在运行它时会出现以下异常

[error java.lang.ClassNotFoundException: net.ucanaccess.jdbc.UcanaccessDriver][1]

0 个答案:

没有答案