How to view derby database using Eclipse Datasource Explorer?

For unit testing, I use a database in memory derby.

Is it possible to connect to this database using a tool such as Eclipse Datasource Explorer when the test runs?

I googled a lot and sometimes found something like:

Connection URL: jdbc: derby: // localhost: 1527 / memory / mydb ...

But that did not work for me.

It says 1527 is the default port.

Is it possible to connect to the memory derby database at all with a tool like eclipse explorer? Does the database open a connection port for connection? Or is there something special I have to set up for this?

Thanks Alex

+6
source share
1 answer

Hi, after some research, I got a solution.

To connect to the embedded derby database, you must run NetworkServerControl in your application. After that, you can connect to the derby database using, for example, Eclipse DTP Plugin / Datasource Explorer.

The code for creating db in memory and for running NSC might 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 must include derby.jar and derbynet.jar that come with jdk7 (lib \ db) in order to be able to create a NetworkServerControl and a database.

After that, you can connect to db while your application (and database) is running. Connection URL: jdbc: derby: // localhost: 1527 / memory: testdb

User and password: your choice

Hi,

Alex

+4
source

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


All Articles