0

I'm new to this site.

I've been having trouble connecting to my Java DB I have created. I've used the following code but given

java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver

as an error.

String url = "jdbc:derby://localhost:1527/db;create=true;user=Administrator";

String driver = "org.apache.derby.jdbc.ClientDriver";

// login and connection details above
try {
    Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
    conn = DriverManager.getConnection(url);
    Statement s = conn.createStatement();

    System.out.println("connected!");
} catch (ClassNotFoundException | SQLException e) {
    JOptionPane.showMessageDialog(null, "error in dbConnection " + e);
    System.out.println(e.toString());
} catch (Exception e) {
    JOptionPane.showMessageDialog(null, "Error in DBconnection , consult developers!");
}

I've tried going through many forums and feeds and none of the advice given seems to work.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Franco D
  • 23
  • 1
  • 1
  • 2
  • 1
    You miss the jar which contains the class as a dependency – Jens Oct 24 '17 at 15:04
  • At minimum show us how you run your application and how your class path is configured. You need to make sure the driver is on the class path used by your application. – Mark Rotteveel Oct 24 '17 at 15:10

1 Answers1

0

You're missing the JAR which contains the class org.apache.derby.jdbc.ClientDriver which is derbyclient.jar

You can download and add this jar to the classpath from here

Or, If you're using maven for building, you can add the following to your pom.xml

<dependency>
    <groupId>org.apache.derby</groupId>
    <artifactId>derbyclient</artifactId>
    <version>10.14.1.0</version>
</dependency>
Sridhar
  • 1,518
  • 14
  • 27