Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have additional connections to Derby (read-only)

What I want to do: My application has a full connection to a Derby DB, and I want to poke around in the DB (read-only) in parallel (using a different tool).

I'm not sure how Derby actually works internally, but I understand that I can have only 1 active connection to a Derby DB. However, since the DB is only consisting of files on my HDD, shouldn't I be able to open additional connections to it, in read-only mode?

Are there any tools to do just that?

like image 843
BennyInc Avatar asked Sep 09 '10 16:09

BennyInc


People also ask

How do I connect to the Derby?

connect 'jdbc:derby:c:\temp\db\FAQ\db'; If you want to connect to a Derby database which is running in server mode then you can use the following command. connect 'jdbc:derby://localhost:1527/c:\temp\db\FAQ\db;create=true';

What is Derby JDBC?

Derby consists of both the database engine and an embedded JDBC driver. Applications use JDBC to interact with a database. Applications running on JDK 1.5 or earlier, must load the driver in order to work with the database. In an embedded environment, loading the driver also starts Derby.


2 Answers

There are two possibilities how to run Apache Derby DB.

  1. Embedded: You run DB within your application → only one connection possible
  2. Client: You start DB as server in separate process → classic DB with many connections

You can recognize the type upon driver size. If the driver has more then 2MB that you use embedded version.

Update

When you startup the derby engine (server or embedded) it gets exclusive access to database files.

If you need to access a single database from more than one Java Virtual Machine (JVM), you will need to put a server solution in place. You can allow applications from multiple JVMs that need to access that database to connect to the server.

For details see Double-booting system behavior.

like image 147
amra Avatar answered Sep 18 '22 16:09

amra


I realize this is an old question, but I thought I might add a little more detail on a solution since links in the currently accepted answer are broken.

It is possible to run the Derby Network Server within a JVM that is using the embedded database already. The code that is using the embedded Derby database doesn't need to change anything and can keep using the DB as is, but with the Derby Network Server started, other programs can connect to derby and access the database.

All you need to do is ensure that derbynet.jar is on the classpath

And then you can do one of the following

  • Include the following line in the derby.properties file: derby.drda.startNetworkServer=true

  • Specify the property as a system property at java start java -Dderby.drda.startNetworkServer=true

  • You can use the NetworkServerControl API to start the Network Server from a separate thread within a Java application: NetworkServerControl server = new NetworkServerControl(); server.start (new PrintWriter(System.out));

More details here: http://db.apache.org/derby/docs/10.9/adminguide/tadminconfig814963.html

Keep in mind that doing this does not enable any security on this connection, so it is not a good idea to do this on a production system. It is possible to add security though and that is documented here: http://db.apache.org/derby/docs/10.9/adminguide/cadminnetservsecurity.html

like image 21
Bert Lamb Avatar answered Sep 17 '22 16:09

Bert Lamb