Derby JDBC

On a Linux with SystemD you can use the following service file (Derby has been installed on /opt/db-derby-10.13.1.1-bin):

[Unit]
Description=Apache Derby Database Network Server
After=network.target

[Service]
Type=simple
Environment=CLASSPATH=/opt/db-derby-10.13.1.1-bin/lib/derby.jar:/opt/db-derby-10.13.1.1-bin/lib/derbynet.jar:/opt/db-derby-10.13.1.1-bin/lib/derbyLocale_cs.jar:/opt/db-derby-10.13.1.1-bin/lib/derbyLocale_de_DE.jar:/opt/db-derby-10.13.1.1-bin/lib/derbyLocale_es.jar:/opt/db-derby-10.13.1.1-bin/lib/derbyLocale_fr.jar:/opt/db-derby-10.13.1.1-bin/lib/derbyLocale_hu.jar:/opt/db-derby-10.13.1.1-bin/lib/derbyLocale_it.jar:/opt/db-derby-10.13.1.1-bin/lib/derbyLocale_ja_JP.jar:/opt/db-derby-10.13.1.1-bin/lib/derbyLocale_ko_KR.jar:/opt/db-derby-10.13.1.1-bin/lib/derbyLocale_pl.jar:/opt/db-derby-10.13.1.1-bin/lib/derbyLocale_pt_BR.jar:/opt/db-derby-10.13.1.1-bin/lib/derbyLocale_ru.jar:/opt/db-derby-10.13.1.1-bin/lib/derbyLocale_zh_CN.jar:/opt/db-derby-10.13.1.1-bin/lib/derbyLocale_zh_TW.jar
WorkingDirectory=/var/lib/derby
StandardOutput=syslog
User=andre
ExecStart=/usr/bin/java -Dderby.system.home=/var/lib/derby org.apache.derby.drda.NetworkServerControl start
ExecStop=/usr/bin/java -Dderby.system.home=/var/lib/derby org.apache.derby.drda.NetworkServerControl shutdown

[Install]
WantedBy=multi-user.target

Copy this file to /usr/lib/systemd/system as apache-derby.service and execute as root:

# systemctl enable apache-derby.service
# systemctl start apache-derby.service

The databases will be generated at /var/lib/derby.

To test the Derby server start the ij tool:

# cd /opt/db-derby-10.13.1.1-bin/bin
# ij

CONNECT 'jdbc:derby://localhome:1527/atest;create=true';

The database atest should be generated within /var/lib/derby/atest. If there is an error, check your apache-derby service and your local firewall (open port 1527).

To use the database server within EOModeler you can set:

database url:      jdbc:derby://<server>:1527/<database name>
JDBC library:      derbyclient.jar
JDBC driver class: org.apache.derby.jdbc.ClientDriver

User Management

Per default Derby doesn’t need an user to access a database. To enable user authentication you should add an user with full access to the database:

# ij

CONNECT 'jdbc:derby://localhome:1527/atest';
CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.user.<an username>', '<a password>');
CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.database.fullAccessUsers', '<an username>');
CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.connection.requireAuthentication', 'true');
EXIT;

If you define an user, you will have to enable the authentication mode for Derby too. Restart the apache-derby.service to enable the authentication after the calls above. Now it is necessary to provide username and password for this specific database “atest” within EOModeler.

The new JDBC url toconnect with ij would be:

CONNECT 'jdbc:derby://<server>:1527/<database name>;user=<username>;password=<secret>';

Leave a Reply