tagged: derby

Apache Derby: Network server

Instead of using Derby as an embedded server you can run it as a network server that multiple clients can connect to.
This is especially useful since with the embedded server you can run ij as the same time as another application is connected to the database.
You can run it using a derbyrun.jar file included with derby:
java -jar /path/to/derby/lib/derbyrun.jar server start

You can shut it down with:
java -jar /path/to/derby/lib/derbyrun.jar server shutdown

Once you start it, the databases will live in the location where you started derby.
And you can connect to it to create a database via:
ij> connect 'jdbc:derby://localhost:1527/somedb;create=true';

By default, the server listens on port 1527.

derby derby-server

Apache Derby setup and ij usage

First download Apache Derby from its website. And put the both to the unzipped folder in your environment, including your PATH.
export DERBY_HOME = /your/path

You also need to set the derby property to say the database is on localhost for the 'ij' property:
export DERBY_OPTS=-Dij.protocol=jdbc:derby://localhost/

Now you should be able to run the 'ij' program. Exit it via issuing 'quit;'.
Open up ij, and create a new database:
ij> CONNECT 'jdbc:derby:firstdb;create=true';

In the current directory you'll have a firstdb/ directory. This constitutes the database. Don't touch the files within!
You can then create a new simple table, insert a value and print the table using the following usual SQL:

ij> create table one (text varchar(500));
0 rows inserted/updated/deleted
ij> insert into one values ('hello');
1 row inserted/updated/deleted
ij> select * from one;

Since ij doesn't have a command history, you may want to issue the commands from the command line instead:
$ echo "connect 'jdbc:derby:firstdb'; select * from one;" | ij
ij version 10.10
ij> ij> TEXT                                                                                                                            

1 row selected

Note we are using the embedded version of Derby. You can access the same database simultaneously. My other post on the network server will help you there.

derby derby-setup

Page 1 of 1