Reputation: 392
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.
Upvotes: 1
Views: 85
Reputation: 381
You should have derbyclient.jar set in the classpath to recognize the driver class (org.apache.derby.jdbc.ClientDriver) you are using.
Upvotes: 0
Reputation: 201429
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.
Upvotes: 2