Search code examples
javanetbeansderby

How to correct java.sql.SQLException: Database 'dbname' not found error?


I am trying to embed a Derby DB in my application using the following code to connect to the database:

                String host = "jdbc:derby:PlayerScores";
                String uName = "user1";
                String uPass = "pass123";

                String driver = "org.apache.derby.jdbc.EmbeddedDriver";
                Class.forName(driver);

                Connection conn = DriverManager.getConnection(host, uName, uPass);

When I test the application and try save the data, the following message comes up:

java.sql.SQLException: Database 'PlayerScores' not found

I have checked my libraries and already have the derby.jarand the derbyclient.jarfiles in place.

I have checked my database name and it is correct.

How can I try correct this problem?


Solution

  • Try to define an absolute path for your database... Example:

    String host = "jdbc:derby:/my/database/path/PlayerScores;create=true";
    

    See this link for more examples...