SQLException: No suitable driver found for url = jdbc: derby

I'm having problems connecting to the local database of the local Apache Derby database (Java DB) for the small game I'm working on. The code that throws the exception is as follows:

public class DatabaseController {

    private static Connection conn;
    private final String url = "url=jdbc:derby://localhost:1527/GameDB;create=true";
    private final String username = "pdc";
    private final String password = "123";

    /**
     * Connects to the database.
     */
    public void initialize() {

        try{
            //Open a connection
            conn = DriverManager.getConnection(url, username, password);

        } catch(SQLException e){
            //Handle errors
            Logger.getLogger(DatabaseController.class.getName()).log(Level.SEVERE, null, e);
        }
    }
}

When I run the code, I get the following exception:

    Oct 08, 2015 2:27:40 PM pdc.project.Controller.DatabaseController initialize
SEVERE: null
java.sql.SQLException: No suitable driver found for url=jdbc:derby://localhost:1527/GameDB;create=true
    at java.sql.DriverManager.getConnection(DriverManager.java:689)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at pdc.project.Controller.DatabaseController.initialize(DatabaseController.java:30)
    at pdc.project.Controller.Main.main(Main.java:35)

Exception in thread "main" java.lang.NullPointerException
    at pdc.project.Controller.DatabaseController.createTable(DatabaseController.java:63)
    at pdc.project.Controller.Main.main(Main.java:36)

I tried the following:

  • Adding derbyclient.jar to libraries (and checking it in the classpath in Project> Properties> Libraries)
  • Adding a Java DB driver to libraries (and checking it in the classpath in Project> Properties> Libraries)
  • Using Class.forName("org.apache.derby.jdbc.ClientDriver")to register a driver
  • Using Class.forName("org.apache.derby.jdbc.EmbeddedDriver")to register a driver
  • Adding a dummy driver

. , , . - , ?

! Netbeans JDK 1.8.

+4
1

URL "url =".

private final String url = "url=jdbc:derby://localhost:1527/GameDB;create=true";

URL- "jdbc:", ,

private final String url = "jdbc:derby://localhost:1527/GameDB;create=true";
+3

Source: https://habr.com/ru/post/1610673/


All Articles