Java SQLException: 找不到适合 jdbc:derby://localhost:1527 的驱动程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3816015/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 05:25:28  来源:igfitidea点击:

SQLException: No suitable driver found for jdbc:derby://localhost:1527

javajdbcderby

提问by Ganesh

I get this error in Netbeans:

我在 Netbeans 中收到此错误:

java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/

How is this caused and how can I solve it?

这是怎么引起的,我该如何解决?

回答by BalusC

The JDBC DriverManagercan't find any suitable Driverfor the given connection URL. Either the JDBC driver isn't loaded at all before connecting the DB, or the connection URL is wrong. Since the connection URL looks fine, I bet that the driver isn't loaded at all. You need to load the driver during application's startup before connecting the DB. For Apache Derby, the driver class name is org.apache.derby.jdbc.ClientDriver. So:

JDBCDriverManager找不到任何适合Driver给定连接 URL 的内容。在连接数据库之前根本没有加载 JDBC 驱动程序,或者连接 URL 错误。由于连接 URL 看起来不错,我敢打赌根本没有加载驱动程序。在连接数据库之前,您需要在应用程序启动期间加载驱动程序。对于 Apache Derby,驱动程序类名称是org.apache.derby.jdbc.ClientDriver. 所以:

Class.forName("org.apache.derby.jdbc.ClientDriver");

回答by Pascal Thivent

java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/

java.sql.SQLException: 找不到适合 jdbc:derby://localhost:1527/ 的驱动程序

This exception has two causes:

这个异常有两个原因:

  • The driver is not loaded.
  • The JDBC URL is malformed.
  • 未加载驱动程序。
  • JDBC URL 格式错误。

In your case, I'd expect to see a database nameat the end of the connection string. For example (use create=trueif you want the database to be created if it doesn't exist):

在您的情况下,我希望在连接字符串的末尾看到一个数据库名称。例如(create=true如果您希望在不存在的情况下创建数据库,请使用):

jdbc:derby://localhost:1527/dbname;create=true

Databases are created by default in the directory where the Network Server was started up. But you can also specify an absolute path to the database location:

默认情况下,在启动网络服务器的目录中创建数据库。但您也可以指定数据库位置的绝对路径:

jdbc:derby://localhost:1527//home/pascal/derbyDBs/dbname;create=true

And just in case, check that derbyclient.jaris on the class path and that you are loading the appropriate driver org.apache.derby.jdbc.ClientDriverwhen working in server mode.

为了以防万一,请检查derbyclient.jar是否在类路径上,以及org.apache.derby.jdbc.ClientDriver在服务器模式下工作时是否加载了适当的驱动程序。

回答by chance

It's also possible that in persistence.xml, EmbeddedDriver was used while the jdbc url was pointing to Derby server. In this case just change the url to pointing a path of database.

也有可能在persistence.xml 中,当jdbc url 指向Derby 服务器时使用了EmbeddedDriver。在这种情况下,只需将 url 更改为指向数据库的路径。

回答by James McMahon

If your using embedded Derby you need Derby.jar in your classpath.

如果您使用嵌入式 Derby,您的类路径中需要 Derby.jar。

回答by Bruno Eberhard

For me

为了我

DriverManager.registerDriver(new org.apache.derby.jdbc.EmbeddedDriver());

helped. In this way, the DriveManager does know the derby EmbeddedDriver. Maybe allocating a new EmbeddedDriver is to heavy but on the other side, Class.forName needs try/catch/doSomethingIntelligentWithException that I dont like very much.

有帮助。这样,DriveManager 就知道了 derby EmbeddedDriver。也许分配一个新的 EmbeddedDriver 很繁重,但另一方面,Class.forName 需要 try/catch/doSomethingIntelligentWithException,我不太喜欢。

回答by csejay

if the database is created and you have started the connection to the, then al you need is to add the driver jar. from the project window, right click on the libraries folder, goto c:programsfiles\sun\javadb\lib\derbyclient.jar. load the file and you should be able to run.

如果创建了数据库并且您已经开始连接,那么您只需要添加驱动程序 jar。在项目窗口中,右键单击库文件夹,转到 c:programsfiles\sun\javadb\lib\derbyclient.jar。加载文件,你应该能够运行。

all the best

祝一切顺利

回答by CounterSpell

I had the same problem when I was writing Java application on Netbeans.Here is the solution:

我在 Netbeans 上编写 Java 应用程序时遇到了同样的问题。这是解决方案:

  1. Find your project in projects selection tab

  2. Right click "Libraries"

  3. Click "Add JAR/Folder..."

  4. Choose "derbyclient.jar"

  5. Click "Open", then you will see "derbyclient.jar" under your "Libraries"

  6. Make sure your URL, user name, pass word is correct, and run your code:)

  1. 在项目选择选项卡中找到您的项目

  2. 右键单击“库”

  3. 单击“添加 JAR/文件夹...”

  4. 选择“derbyclient.jar”

  5. 单击“打开”,然后您将在“库”下看到“derbyclient.jar”

  6. 确保您的 URL、用户名、密码正确,然后运行您的代码:)

回答by Devy

Notice: you can download it from here.

注意:您可以从这里下载。

If you can't find it, then

如果你找不到它,那么

  1. Find your project in projects selection tab

  2. Right click "Libraries"

  3. Click "Add JAR/Folder..."

  4. Choose "derbyclient.jar"

  5. Click "Open", then you will see "derbyclient.jar" under your "Libraries"

  1. 在项目选择选项卡中找到您的项目

  2. 右键单击“库”

  3. 单击“添加 JAR/文件夹...”

  4. 选择“derbyclient.jar”

  5. 单击“打开”,然后您将在“库”下看到“derbyclient.jar”

Make sure your URL, user name, password is correct, and run your code:)

确保您的 URL、用户名、密码正确,然后运行您的代码:)

回答by lemic

The question is answered but providing a command line for illustration. This worked for me when I was trying a as simple as possible test to connect to network mode derby.

问题得到了回答,但提供了一个命令行进行说明。当我尝试尽可能简单的测试以连接到网络模式 derby 时,这对我有用。

  • Driver loaded in app with:Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();

  • The connection URL was: "jdbc:derby://localhost:1527/myDB;create=true"

  • I ran my app using: java -classpath derbyclient.jar:. myAppClass

  • 应用程序中加载的驱动程序:Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();

  • 连接 URL 是:“jdbc:derby://localhost:1527/myDB;create=true”

  • 我运行我的应用程序使用:java -classpath derbyclient.jar:。我的应用类

回答by dafilipaj

I tried everything mentioned in this thread and only .registerDriver() worked for me. This is how my part of code looks now:

我尝试了这个线程中提到的所有内容,只有 .registerDriver() 对我有用。这就是我的代码部分现在的样子:

DriverManager.registerDriver(new org.apache.derby.jdbc.ClientDriver());
connection = DriverManager.getConnection(url, user, pass);

Notice that the problem wasn't in embedded Derby.

请注意,问题不在嵌入式 Derby 中。