好吧,这有点奇怪,我成功安装了驱动程序,在服务选项卡中,我的数据库表正确显示,但是当我从代码中调用驱动程序时,我得到:
java.sql.SQLException: No suitable driver found for jdbc:ucanaccess://C:\Users\sample.mdb
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at sampleProject.TestDBConnection.main(TestDBConnection.java:16)
这是我的代码:
package sample;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class TestDBConnection {
public static void main(String[] args) {
try
{
// Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
System.out.println("sample.mdb");
Connection conn=DriverManager.getConnection("jdbc:ucanaccess://C:\\Users\\sample.mdb");
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("SELECT * FROM tableSample");
while(rs.next())
System.out.println(rs.getString("RunnersSample") );
} catch(Exception ex) {
ex.printStackTrace();
}
}
}
任何人都知道为什么我不能从代码访问?提前致谢!