1

I want to connect to a database on my computer. I have already created a database, but i cannot connect. I always get a classnotfoundexception. I don't know how to fix it. My database is called begindb and I want to use org.apache.jdbc.ClientDriver as driver. This is my code from my program:

private final static String JDBC_URL="jdbc:derby://localhost/begindb";
private final static String JDBC_DRIVER="org.apache.derby.jdbc.ClientDriver";
private final static String USER_ID="test";
private final static String PASSW="test";
public static void main(String[] args) {
    try{
        Class.forName(JDBC_DRIVER);
        try(Connection conn = DriverManager.getConnection(JDBC_URL, USER_ID, PASSW)){
            System.out.println("good job!!");
        }
        catch(SQLException e){
            System.out.println("Error.");
        }
    }
    catch(ClassNotFoundException e)
        System.out.println(e.getMessage());
    }
}

So the first line in the try statement won't work. Because i am getting a classnotfoundexception.

f_puras
  • 2,521
  • 4
  • 33
  • 38
Lennart
  • 383
  • 4
  • 16

2 Answers2

2

From the documentation Step 4 -

To use the Derby Network Client JDBC driver, set your CLASSPATH to include the jar files listed below:

derbyclient.jar: contains the JDBC driver

derbytools.jar: optional, provides the ij tool

Add derbyclient.jar to your project classpath.

  1. Expand you Project.
  2. Right-click Libraries.
  3. Select Add Jar/Folder.
  4. Select "derbyclient.jar"
Community
  • 1
  • 1
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • Thanks a lot. This worked. After i had done this i faced another prob with the connection, but if i added my port number to my JDBC_URL it worked. Thanks – Lennart Jun 18 '14 at 15:22
0

You should have derbyclient.jar set in the classpath to recognize the driver class (org.apache.derby.jdbc.ClientDriver) you are using.

user3684675
  • 381
  • 4
  • 8
  • 32