0

I'm getting the following error (Note: I am using Netbeans):

java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:7001/LF_JHU_DERBY
at java.sql.DriverManager.getConnection(DriverManager.java:596)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at randomtests.UFTest.main(UFTest.java:38)

The relevant part of my code is:

Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
DriverManager.getConnection("jdbc:derby://localhost:7001/JP_JHU_DERBY", username, password);

I have the derby.jar file in my Java/Extensions directory--without that the embedded driver was not being found. So I have a few Q's:

  1. Shouldn't it have a JDBC driver from the Class.forName() method? Why have problems all of a sudden at getConnection()?

  2. I thought I didn't even have to load a driver with the newer JDK's. I am using Netbeans and (succesfully, I think) set the netbeans.conf file to the latest JDK (with "netbeans_jdkhome="/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home"). What am I missing?

Jo.P
  • 1,139
  • 4
  • 15
  • 35
  • Have you taken a look at this: http://stackoverflow.com/a/15459364/877472 – Paul Richter Feb 04 '14 at 17:17
  • Regarding netbeans.conf: that configuration is only there to run NetBeans it is not necessarily the JDK used for your project. –  Feb 04 '14 at 17:20

1 Answers1

1

Apache Derby can be run in two different modes:

  1. as a network server
  2. inside the JVM in memory.

The driver org.apache.derby.jdbc.EmbeddedDriver can only handle in-memory databases. The URL for that has the format "jdbc:derby:/path/to/database".

But your URL is one for a network server, which isn't handled by the embedded driver. To connect to a derby server, you have to use the driver class org.apache.derby.jdbc.ClientDriver

  • First, thanks for helping! Now...I put ClientDriver in the Class.forName() and now it's throwing ClassNotFound…But shouldn't having derby.jar in Java/Extensions resolve this? (Like it did when I was using the embedded driver?) – Jo.P Feb 04 '14 at 18:06
  • @Jo.P: maybe your JDK was installed without JavaDB (it can be de-selected during installation - something I usually do as well) –  Feb 04 '14 at 18:09
  • It is part of the Derby "stuff", yes. So maybe you didn't add the correct jar file to your classpath. You need to add `derby.jar` –  Feb 04 '14 at 18:49
  • I just tried "sun.jdbc.odbc.JdbcOdbcDriver" and ClassNotFound…so maybe what you said is correct, although I still don't see how it relates to the derby stuff which I do have :( – Jo.P Feb 04 '14 at 18:49
  • @Jo.P `sun.jdbc.odbc.JdbcOdbcDriver` is part of the Java Runtime. That should *not* give you a ClassNotFoundException unless you are running Java **8** where the JDBC/ODBC bridge was removed. –  Feb 04 '14 at 18:50
  • Well, Java -version returns with: "java version "1.7.0_51" Java(TM) SE Runtime Environment (build 1.7.0_51-b13) Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)" So…There's something really odd going on, then. Any ideas? Thanks for all your time/help, btw! – Jo.P Feb 04 '14 at 19:06