Reputation: 89
I've noticed that there are a lot of people here who already asked same question, so I tried to follow the solutions that people suggested. However, I'm still struggling with an error below.. Please advise!
"myDB" which is the table I created and already inserted some rows. And it is in my eclipse project folder.
ps. Java and Javac command works so I think the environment setting is set.
code:
try {
Class.forName("org.apache.derby.jdbc.ClientDriver");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
Connection conn = DriverManager.getConnection("jdbc:derby:myDB");
System.out.println(conn);
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM marathon");
and error:
java.sql.SQLException: No suitable driver found for jdbc:derby:myDB
at
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:702)
at
java.sql/java.sql.DriverManager.getConnection(DriverManager.java:251)
at Main.actionPerformed(Main.java:166)
.
.
.
Your help would be very appreciated and thanks in advance.
Upvotes: 1
Views: 677
Reputation: 16359
Since your URL is jdbc:derby:myDB
, which is the Embedded Derby syntax, you need to have derby.jar
in your CLASSPATH
, and then Derby will open the embedded database located in the folder myDB
relative to the current working directory of your program.
If you really wanted to use the Client/Server version of Derby, with the ClientDriver
as your JDBC driver, then you need to change your Connection URL syntax to use the client-server syntax, and you need to have the Derby Network Server running.
Here's a tutorial which will help you get started and understand all these concepts: https://db.apache.org/derby/docs/10.14/getstart/
Upvotes: 2