我有驱动器derbyclient.jar
在我的图书馆中,但它仍然找不到我的数据库。我只是无法连接到数据库。
String host = "jdbc:derby://localhost:1527/prosto";
String uName = "username";
String uPass = "password";
Connection con = DriverManager.getConnection(host, uName, uPass);
最佳答案
您首先需要加载 derby 驱动程序类。为此,请在 DriverManager.getConnection()
调用之前添加此代码。
try{
Class.forName("org.apache.derby.jdbc.ClientDriver");// or may be it is "org.apache.derby.jdbc.EmbeddedDriver"? Not sure. Check the correct name and put it here.
} catch(ClassNotFoundException e){
//handle exception
}
这将在 JDBC 驱动程序注册表中加载并注册 Derby 驱动程序类,之后您将能够连接到数据库。
请参阅此了解更多详细信息:
https://db.apache.org/derby/docs/10.4/devguide/cdevdvlp40653.html
Update
derby 安装的 lib 文件夹中应该有一个 derbyclient.jar
。您还需要将其添加到类路径中并使其在运行时可用。这似乎解决了我的问题。
希望这有帮助!
关于java - 找不到适用于 jdbc :derby://localhost:1527/prosto 的合适驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41238457/