[英]Exception in thread “main” java.sql.SQLException: No suitable driver found for jdbc:ucanaccess://C:/Users/gfas1/Desktop/st.accdb
So I'm trying to set up the connection in access database but otherwise fails.所以我试图在访问数据库中建立连接,但否则失败。 I have imported the ucanaccess 5 files already and I'm confused why this doesn't work.我已经导入了 ucanaccess 5 个文件,我很困惑为什么这不起作用。 Here are the jars这里是 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);
}
}
}
JDBC driver should be loaded and you should have driver jar in your classpath应该加载 JDBC 驱动程序,并且您的类路径中应该有驱动程序 jar
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver"); Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
In this case driver registers itself and Java knows how to handle those database connection.在这种情况下,驱动程序会自行注册,并且 Java 知道如何处理这些数据库连接。
also see http://ucanaccess.sourceforge.net/site.html另见http://ucanaccess.sourceforge.net/site.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.