Ganesh
Ganesh

Reputation: 331

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

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?

Upvotes: 33

Views: 160301

Answers (19)

Roman
Roman

Reputation: 315

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

Upvotes: 0

Khamaseen
Khamaseen

Reputation: 374

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

Upvotes: 1

Ayush Shridhar
Ayush Shridhar

Reputation: 125

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.

Upvotes: 0

peterong
peterong

Reputation: 103

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.

Upvotes: 0

subho
subho

Reputation: 31

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';

Upvotes: 0

Amit Kaneria
Amit Kaneria

Reputation: 5808

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

Upvotes: 0

Amit Kaneria
Amit Kaneria

Reputation: 5808

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

Upvotes: 1

ntombela
ntombela

Reputation: 1388

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

Upvotes: 0

Mohamed Bawaneen
Mohamed Bawaneen

Reputation: 29

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 !

Upvotes: 2

dafilipaj
dafilipaj

Reputation: 1074

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.

Upvotes: 0

lemic
lemic

Reputation: 197

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

Upvotes: 2

Devy
Devy

Reputation: 248

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

Upvotes: 20

CounterSpell
CounterSpell

Reputation: 123

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

Upvotes: 4

csejay
csejay

Reputation: 11

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

Upvotes: 0

Bruno Eberhard
Bruno Eberhard

Reputation: 1704

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.

Upvotes: 11

James McMahon
James McMahon

Reputation: 49649

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

Upvotes: 2

chance
chance

Reputation: 6507

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.

Upvotes: 0

Pascal Thivent
Pascal Thivent

Reputation: 570565

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.

Upvotes: 26

BalusC
BalusC

Reputation: 1109432

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");

Upvotes: 5

Related Questions