Cool Hand Luke
Cool Hand Luke

Reputation: 11

Derby db connectivity problems

I receive the following error msg when attempting to connect to a derby network server:

java.sql.SQLException: No suitable driver found for jdbc:derby://localhost/studentdb;create=true

Derby is properly installed and all environment variables set. I am able to start the derby NetworkServerControl from a Windows command prompt with the following command:

java org.apache.derby.drda.NetworkServerControl start -h localhost

,and I can do this from any location within my system's directory tree.

I can start the derby ij client from within a Windows command prompt with the command:

java org.apache.derby.tools.ij

,again, from any location within my system's directory tree.

But the code snippet below is unable to make this connection:

    public static void main(String[] args) {
    Connection conn = null;

        String url = "jdbc:derby://localhost/studentdb;create=true";

    //the error happens here, the program executes no further
        conn = DriverManager.getConnection(url,null);

        Statement stmt = conn.createStatement();

}

Placing the port value in the url string makes no difference. Any suggestions would be much appreciated.

Upvotes: 1

Views: 1411

Answers (2)

Sriesh Agrawal
Sriesh Agrawal

Reputation: 21

So I encountered this error and it was quite an irritating and hectic task to resolve this. But in the end, I managed to find a perfect video that made me install derby from the start and guided me perfectly on how to install it. However, there is one more step after the video.

Watch this video if you have set up JavaFX packages and are able to run the program normally, but facing "java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/DBNAME;create=true" issue when trying to run with the database.

Link to the tutorial -> https://www.youtube.com/watch?v=OKiBsWbgrMw

Now after this is set up you will now be able to start/stop the database (via the services tab) and will be able to connect with the DB. But the issue will still persist in trying to edit the DB.

To rectify this, follow the steps ->

Right click on project ---> Properties ---> Libraries ---> Click on '+' in Classpath ---> Add jar/folder ---> Go to the lib folder inside the derby and select derbyclient.jar

VERSIONS

JAVA - 17.0.1, Netbeans - 12.6

Upvotes: 0

Olivier Boissé
Olivier Boissé

Reputation: 18093

You must add the derby jdbc driver to your classpath (from derbyclient.jar, since this is the ClientDriver), then use this instruction to load the driver :

Class.forName("org.apache.derby.jdbc.ClientDriver");

Upvotes: 1

Related Questions