Derby Network Server sample program

The Network Server sample demo program (NsSample) is a simple JDBC application that interacts with the Derby Network Server. The program:

The following files should be installed in the %DERBY_INSTALL%\demo\programs\nserverdemo\ directory in order to run the sample program:

Running the Network Server demo program

To run the Derby Network Server demonstration program:

  1. Open a command prompt and change directories to the %DERBY_INSTALL%\demo\programs\ directory, where %DERBY_INSTALL% is the directory where you installed Derby.
  2. Set the CLASSPATH to the current directory (".") and also include the following jar files in order to use the Derby Network Server and the DB2 JDBC Universal Driver.
  3. Test the CLASSPATH settings by running the following java command:
    java org.apache.derby.tools.sysinfo
    This command will show the Derby jar files that are in the CLASSPATH as well as the DB2 JDBC Universal Driver along with their respective versions.
  4. Once you have set up your environment correctly, execute the application from the
    %DERBY_INSTALL%\demo\programs\ directory:
    java nserverdemo.NsSample
You should receive output similar to the following if the program runs successfully:

Derby Network Server created
[NsSample] Unable to obtain a connection to network server, trying again after 3000 ms.
Server is ready to accept connections on port 1621.
Connection number: 1.
[NsSample] Derby Network Server started.
[NsSample] Sample Derby Network Server program demo starting.
Please wait .....................
Connection number: 2.
[NsSampleWork] Table 'SAMPLETBL' already exists; no need to create schema again.
[NsSampleClientThread] Thread id - 1; started.
[NsSampleWork] Thread id - 1; requests database connection, dbUrl =jdbc:derby:NSSampledb;
[NsSampleClientThread] Thread id - 2; started.
[NsSampleWork] Thread id - 2; requests database connection, dbUrl
=jdbc:derby:net://localhost:1621/NSSampledb;create=true:retrieveMessagesFromServerOnGetMessage=true;deferPrepares=true;
Connection number: 3.
[NsSampleWork] Thread id - 1 selected 1 row [61,Derby28 ,3.20918E21,9854]
[NsSampleWork] Thread id - 1; inserted 1 row.
[NsSampleWork] Thread id - 1; deleted 1 row with t_key = 9854
[NsSampleWork] Thread id - 1; inserted 1 row.
[NsSampleWork] Thread id - 1; deleted 1 row with t_key = 9818
[NsSampleWork] Thread id - 2; deleted 0 row with t_key = 9854
[NsSampleWork] Thread id - 1; updated 1 row with t_key = 9481
[NsSampleWork] Thread id - 1; updated 1 row with t_key = 9481
[NsSampleWork] Thread id - 1; updated 0 row with t_key = 9481
[NsSampleWork] Thread id - 2; deleted 1 row with t_key = 9481
[NsSampleWork] Thread id - 1; inserted 1 row.
[NsSampleWork] Thread id - 1; updated 1 row with t_key = 9150
[NsSampleWork] Thread id - 1; closed connection to the database.
[NsSampleClientThread] Thread id - 1; finished all tasks.
[NsSampleWork] Thread id - 2 selected 1 row [57,Derby18 ,7.873628,9150]
[NsSampleWork] Thread id - 2; updated 1 row with t_key = 9150
[NsSampleWork] Thread id - 2 selected 1 row [58,Derby18 ,7.873628,9150]
[NsSampleWork] Thread id - 2; inserted 1 row.
[NsSampleWork] Thread id - 2 selected 1 row [58,Derby18 ,7.873628,9150]
[NsSampleWork] Thread id - 2; inserted 1 row.
[NsSampleWork] Thread id - 2; updated 1 row with t_key = 9150
[NsSampleWork] Thread id - 2 selected 1 row [61,Derby18 ,7.873628,9150]
[NsSampleWork] Thread id - 2; closed connection to the database.
[NsSampleClientThread] Thread id - 2; finished all tasks.
[NsSample] Shutting down network server.
Connection number: 4.
Shutdown successful.
[NsSample] End of Network server demo.

Running the demo program will also create new directories and files: