How to browse a derby memory database with Eclipse Datasource Explorer?

送分小仙女□ 提交于 2019-12-07 03:20:52

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/11796697/how-to-browse-a-derby-memory-database-with-eclipse-datasource-explorer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!