找不到适用于jdbc:derby://localhost:1527/prosto的驱动程序 [英] No suitable driver found for jdbc:derby://localhost:1527/prosto
问题描述
我的库中有驱动器 derbyclient.jar
,但是仍然找不到我的数据库.我只是无法连接到数据库.
I have drive derbyclient.jar
in my libraries but it's still not finding my database. I just can't connect to database.
String host = "jdbc:derby://localhost:1527/prosto";
String uName = "username";
String uPass = "password";
Connection con = DriverManager.getConnection(host, uName, uPass);
推荐答案
您首先需要加载derby驱动程序类.为此,请在 DriverManager.getConnection()
调用之前添加此代码.
You will first need to load the derby driver class. To do that, add this code before the DriverManager.getConnection()
call.
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驱动程序类,之后,您将可以连接到数据库.
This will load and register the Derby driver class in the JDBC's driver registry, after which you'll be able to connect to the database.
请参阅此以获取更多详细信息:
Refer to this for more details:
https://db.apache.org/derby/docs/10.4/devguide/cdevdvlp40653.html
更新
在derby安装的lib文件夹中应该有一个 derbyclient.jar
.您还需要将其添加到类路径中,并使其在运行时可用.这似乎为我解决了问题.
There should be a derbyclient.jar
in the lib folder of derby installation. You will need to add that also to the class path and make it available at run time. This seems to solve the problem for me.
希望这会有所帮助!
这篇关于找不到适用于jdbc:derby://localhost:1527/prosto的驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!