我想将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]