How to install Derby in a client/server mode with the Network server mode? (JavaDB)

Card Puncher Data Processing

About

Derby (ie Java DB) has two types environment and then two types of installation. This article goes over an installation in the client/server architecture with the installation of Java DB within the Network Server.

To get more details on the application-embedded installation, check the getting started article.

Server

Setting the DERBY_HOME

The DERBY_HOME Environment variable is a variable that store the location of the Derby bin directory.

With a java installation, the DERBY_HOME environment variable is JAVA_HOME/db.

SET DERBY_HOME=C:\Program Files\Java\jdk1.7.0\db

PATH

Add the DERBY_HOME/bin directory to the PATH environment variable so that you can run the Derby scripts from any directory.

Path Bin Derby Home

Classpath

Add the derbyrun.jar jar file to your server classpath:

The derbyrun.jar archive adds in the classpath all other Derby jar:

  • derbynet.jar. This jar file contains the Network Server code. It contains the Network Server class.
  • derby.jar. This jar file contains the Derby database engine code. It must be in the classpath in order for the Network Server to access Derby databases. derby.jar is included in the Class-Path attribute of derbynet.jar's manifest file.

All jar files are in the $DERBY_HOME/lib directory.

Derby provides script files for setting this classpath.They are located in the $DERBY_HOME/bin directory.

  • setNetworkServerCP.bat (Windows)
  • setNetworkServerCP (UNIX)
setNetworkServerCP.bat
SET DERBY_INSTALL=C:\PROGRA~1\Java\JDK17~1.0_0\db
set CLASSPATH=C:\Program Files\Java\jdk1.7.0_04\db\lib\derbynet.jar;C:\Program Files
\Java\jdk1.7.0_04\db\lib\derbytools.jar;C:\TimesTen\TT1122~1\lib\ttjdbc5.jar;

Starting the Network Server

To start the Network Server, you can invoke a script, a jar file, or a class.

Specify a port number other than the default (1527)

"%DERBY_HOME%/bin/startNetworkServer" -h HI-LAPTOP-NGD -p 1368

where:

  • myhost is the host name or IP address.
  • p is the portnumber (default 1527)

Before using the -h option, you should run under the Java security manager with a customized security policy and you should enable user authentication.

By default, the Network Server will listen to requests only on the loopback address, which means that it will only accept connections from the local host.

Console output:

Thu Oct 25 20:47:18 CEST 2012 : Security manager installed using the Basic server security policy.
Thu Oct 25 20:47:19 CEST 2012 : Apache Derby Network Server - 10.8.2.2 - (1181258) started and ready
 to accept connections on port 1368

Shutting Down the Network Server

cd %DERBY_HOME%\lib
java -jar derbyrun.jar server shutdown -h  HI-LAPTOP-NGD -p 1368
Thu Oct 25 20:50:30 CEST 2012 : Apache Derby Network Server - 10.8.2.2 - (1181258) shutdown

Client

The derbyclient.jar jar file contains the Derby Network Client JDBC driver that is necessary to communicate with the Network Server. It must be in the class path of the application on the client side in order to access Derby databases over a network.

Derby provides script files for setting the classpath to work with the Network Server. The scripts are located in the $DERBY_HOME/bin directory.

  • setNetworkClientCP.bat (Windows)
  • setNetworkClientCP (UNIX)

Connection

With a standard installation, the user authentication is not enabled.

Eclipse

Javadb Derby Eclipse Jdbc Connection Properties

Support:

CREATE TABLE TEST_TABLE
Syntax error: Encountered "<EOF>" at line 1, column 23.
Elapsed Time:  0 hr, 0 min, 0 sec, 0 ms.

This problem comes from the “Execute Current Text” operation. You expect that it will call the complete statement but in fact Eclipse will call the line where the cursor is. In the above example it has called only “CREATE TABLE TEST_TABLE”.

IJ

Java DB - IJ

set DERBY_OPTS=-Dij.protocol=jdbc:derby://localhost:1527/
ij
ij version 10.8
ij> connect 'jdbc:derby://localhost:1527/sample;create=true';
ij> CREATE TABLE FIRSTTABLE
    (ID INT PRIMARY KEY,
> >     NAME VARCHAR(12));
0 rows inserted/updated/deleted

Documentation / Reference





Discover More
Card Puncher Data Processing
Apache Derby (JavaDB)

Derby is a relational database written purely in the Java programming language. Java DB is based on and is compatible with the open source Apache Derby database. (Java DB is the Oracle release of the...



Share this page:
Follow us:
Task Runner