For unit testing I use a derby in-memory database.
Is there any chance to connect to this database using a tool like Eclipse Datasource Explorer when the test is running?
I googled a lot and sometimes I found something like:
Connection-URL: jdbc:derby://localhost:1527/memory/mydb...
But it did not work for me.
It says that 1527 is the default port.
Is it possible at all to connect to a derby memory database with a tool like eclipse explorer? Does the database open a connection-port to connect to? Or is there something special I have to configure for this to work?
Thanks, Alex
Hi after some more research I got the solution.
To connect to a embedded derby memory database you have to start the NetworkServerControl in your application. After that you are able to connect to the derby database by using for example the eclipse DTP Plugin / Datasource Explorer.
The code to create the in-memory db and to start the NSC could look like this:
public static void main(String args[])
{
NetworkServerControl nsc = new NetworkServerControl(InetAddress.getByName("localhost"), 1527);
nsc.start(new PrintWriter(System.out, true));
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
Connection c = DriverManager.getConnection("jdbc:derby:memory:testdb;create=true");
}
You have to include the derby.jar & derbynet.jar that comes with the jdk7 (lib\db) to be able to create the NetworkServerControl and the database.
After that you can connect to the db as long as your application (and the database) is running. Connection-URL is: jdbc:derby://localhost:1527/memory:testdb
User and Password: your choice
Regards,
Alex
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With