Search code examples
javaderby

Open embbeded Derby DB while debbunging


I have have an embbeded derby db in my application.

if (new File(database).exists()) {
        connection = DriverManager.getConnection("jdbc:derby:" + database);
} else {
        connection = DriverManager.getConnection("jdbc:derby:" + database + ";create=true");
}

With JPA i can open the DB and work with it. Now I would like to look inside the DB while debbuging. I am using Netbeans.

What I tried: Start the app and go to Services -> Databases -> New Connection --> Java DB (embedded) and choose derby as driver --> specified the JDBC URL (in same why like in the persistence.xml which work)

But then I get the Error: "Cannot establish a connection to jdbc:derby:swot usering EmbeddedDriver (Die Datenbank 'swot' wurde nicht gefunden.)" last part in english: "Database "swot" not found."

Have I to allow the access somehow?


Solution

  • Your NetBeans URL should be 'jdbc:derby:/full/path/to/database/file'. This will let NetBeans connect if your application is NOT running.

    Embedded derby only allows one JVM to connect to the database at a time. So you would be unable to have your application connected to the database at the same time as NetBeans.

    To have multiple JVMs connected at the same time, you must instead run derby in client/server mode. The Derby URL would look like 'jdbc:derby://localhost:1527/MyDbTest'. See Derby Network Server for all the details of starting and configuring the Derby server.