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

19

32

I get this error in Netbeans:

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

How is this caused and how can I solve it?

Academician answered 28/9, 2010 at 18:46 Comment(1)
Possible duplicate of The infamous java.sql.SQLException: No suitable driver foundSexagesima
C
26

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

This exception has two causes:

  • The driver is not loaded.
  • The JDBC URL is malformed.

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

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.jar is on the class path and that you are loading the appropriate driver org.apache.derby.jdbc.ClientDriver when working in server mode.

Coupon answered 29/9, 2010 at 1:39 Comment(0)
S
20

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"

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

Scrophulariaceous answered 27/9, 2012 at 9:27 Comment(0)
S
11

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.

Spradlin answered 9/2, 2012 at 8:27 Comment(1)
Normal application code should not call DriverManager.registerDriver. That method is for JDBC drivers to call when they register themselves. The correct way to load a JDBC driver is through automatic driverloading or explicitly loading the driver class with Class.forName("org.apache.derby.jdbc.EmbeddedDriver").Vang
S
5

The JDBC DriverManager can't find any suitable Driver for 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:

Class.forName("org.apache.derby.jdbc.ClientDriver");
Sexagesima answered 28/9, 2010 at 18:51 Comment(2)
Actually I think they are using the ClientDriver, not the EmbeddedDriver, based on the connection URL. So it should be org.apache.derby.jdbc.ClientDriver.Stedt
Switching to derbyclient.jar instead of derby.jar for my networked derby instance was my problem as well.Nessie
M
4

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

  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:)

Mccammon answered 19/8, 2012 at 14:10 Comment(0)
C
2

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

Cramp answered 20/7, 2011 at 15:35 Comment(0)
S
2

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.

  • 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

Stature answered 15/12, 2013 at 0:11 Comment(0)
S
2

I solved this by adding library to the library console below my project:

  • Right click and then add library
  • add JAVA DB DRIVER.

My project is working !

Sphagnum answered 3/7, 2014 at 8:39 Comment(0)
U
1

I was facing the same issue. I was missing DriverManager.registerDriver() call, before getting the connection using the connection URL and user credentials.

It got fixed on Linux as below:

DriverManager.registerDriver(new org.apache.derby.jdbc.ClientDriver());
connection = DriverManager.getConnection("jdbc:derby://localhost:1527//tmp/Test/DB_Name", user, pass);

For Windows:

DriverManager.registerDriver(new org.apache.derby.jdbc.ClientDriver());
connection = DriverManager.getConnection("jdbc:derby://localhost:1527/C:/Users/Test/DB_Name", user, pass);
Upmost answered 7/12, 2015 at 18:44 Comment(0)
H
1

Had the same, and it was solved by running with the classpath defining the derby.jar location.

java -cp <path-to-derby.jar> <Program>

To be more precise:

java -cp "lib/*:." Program

Where :. includes the current directory. And the lib/* does not include the jar extension (lib/*.jar).

Heparin answered 15/10, 2020 at 14:47 Comment(0)
C
0

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.

Crowning answered 10/5, 2011 at 11:27 Comment(0)
C
0

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.

all the best

Calliecalligraphy answered 15/5, 2012 at 13:50 Comment(0)
S
0

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

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

Notice that the problem wasn't in embedded Derby.

Siding answered 11/5, 2014 at 0:24 Comment(0)
P
0

You can also get the same error if the Java DB server has not been started.

Patrizius answered 7/8, 2014 at 6:25 Comment(0)
U
0

You may be missing to start the Derby server. Once a derby server starts, it starts listening to default port 1527.

Start script is located as below:

Windows:

    <DERBY_INSTALLATION_DIRECTORY>/bin/startNetworkServer.bat

Linux:

    <DERBY_INSTALLATION_DIRECTORY>/bin/startNetworkServer
Upmost answered 5/1, 2016 at 20:14 Comment(0)
D
0

This error occurs when the syntax of connection string is not valid.

You can use the connection string as

'jdbc:derby:MyDbTest;create=true'

or

you can use the following command in the command prompt, the command below creates a new database called MyDbTest succesfully:

connect 'jdbc:derby:MyDbTest;create=true';
Dimpledimwit answered 1/4, 2017 at 17:51 Comment(0)
D
0

I just bumped into this problem, tried all above suggestions but still failed. Without repeat what have been suggested above, here are the things I (you) may be missing: In case you are using maven, likely you'll state the dependencies i.e:

<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.10.1.1</version>

Please be careful with the version. It must be compatible with the server instance you are running.

I solved my case by giving up on what maven dependencies provided and manually adding external jar from "%JAVA_HOME%\db\lib", the same source of my running server. In this case I'm testing using my Local.

So if you're testing with remote server instance, look for the derbyclient.jar that come with server package.

Denyse answered 8/6, 2017 at 21:12 Comment(0)
I
0

Encountered the same problem. I was doing something like:

connect 'jdbc:derby://localhost:1527/~/databases/db1'

Replacing the path with the absolute path fixed this problem:

connect 'jdbc:derby://localhost:1527//Users/ayush99/databases/db1'.

In summary: Avoid using ~ or any such variables in the path of existing database.

Insoluble answered 7/7, 2020 at 11:28 Comment(0)
S
0

I used the above answers and nothing worked. What worked for me was to put the dependencies into the project, like its said above.

Then go in the dependencies folder, right click on the dependencies derbyshared.jar and derbyclient.jar and "add local sources". Connect the two dependencies with the local jar files in your derby folder and its done. Maybe only a Netbeans problem

Steel answered 25/9, 2021 at 11:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.