tags:

views:

64

answers:

3

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?

A: 

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");
BalusC
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.
Bryan Pendleton
Fixed, thanks :)
BalusC
A: 

Make sure that derbyclient.jar is in your classpath.

Bryan Pendleton
It would have produced a `ClassNotFoundException` rather than a `SQLException`. That is, when his exception handling is done properly.
BalusC
+1  A: 

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.

Pascal Thivent