我的数据库不起作用,我收到错误,我在代码后粘贴了
try {
String url = "jdbc:derby:test";
String name = "root";
String password = "123";
Connection con = DriverManager.getConnection(url, name, password);
Statement state = con.createStatement();
String query = "INSERT INTO APP.UNTITLED (id , name , password ) VALUES (1, 'Anas','123456789')";
state.execute(query);
}
catch (SQLException e){
e.printStackTrace();
}
}
}
这是出现的错误:
java.sql.SQLException: No suitable driver found for jdbc:derby:test
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at testdatabase.TestDatabase.main(TestDatabase.java:25)
BUILD SUCCESSFUL (total time: 0 seconds)
答案 0 :(得分:0)
您必须使用Class.forName
查找类路径才能找到合适的驱动程序。
try {
...
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
Connection con = DriverManager.getConnection(url, name, password);
Statement state = con.createStatement();
...
}
catch (....
不要忘记将库添加到项目中
java DB驱动程序
以下jar文件。
<强>的derby.jar
derbyclient.jar中
derbynet.jar 强>