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:

  1. Starts the Derby Network Server.
  2. Connects to the Network Server and creates the database if not already created. The Network Client driver is loaded automatically.
  3. Checks to see if the schema is already created, and if not,
  4. Creates the schema, which includes the SAMPLETBL table and corresponding indexes.
  5. Connects to the database.
  6. Loads the schema by inserting data.
  7. Starts client threads to perform database related operations.
  8. Has each of the clients perform DML operations (select, insert, delete, update) using JDBC calls; in particular, one client opens an embedded connection to perform database operations, while the other client opens a client connection to the Derby Network Server to perform database operations.
  9. Waits for the client threads to finish the tasks.
  10. Shuts down the Derby Network Server at the end of the demo.

The following files in the DERBY_INSTALL\demo\programs\nserverdemo\ directory are needed to run the sample program (DERBY_INSTALL is the directory where you installed Derby):

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.
  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 Derby Client Network JDBC 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 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 [driverType]
You should receive output similar to the following if the program runs successfully:

Using JDBC driver: org.apache.derby.jdbc.ClientDriver
Derby Network Server created
Apache Derby Network Server started and ready to accept connections on port 1621
[NsSample] Derby Network Server started.
[NsSample] Sample Derby Network Server program demo starting.
Please wait .....................
[NsSampleWork] Begin creating table - SAMPLETBL and necessary indexes.
[NsSampleClientThread] Thread id - 2; started.
[NsSampleWork] Thread id - 2; requests database connection, dbUrl =jdbc:derby://localhost:1621/NSSampledb;create=true;
[NsSampleClientThread] Thread id - 1; started.
[NsSampleWork] Thread id - 1; requests database connection, dbUrl =jdbc:derby:NSSampledb;
[NsSampleWork] Thread id - 1; inserted 1 row.
[NsSampleWork] Thread id - 1; inserted 1 row.
[NsSampleWork] Thread id - 1; deleted 1 row with t_key = 9372
[NsSampleWork] Thread id - 1 selected 1 row [920,Derby50 ,951.7808,9216]
[NsSampleWork] Thread id - 1 selected 1 row [920,Derby50 ,951.7808,9216]
[NsSampleWork] Thread id - 1; inserted 1 row.
[NsSampleWork] Thread id - 1 selected 1 row [920,Derby50 ,951.7808,9216]
[NsSampleWork] Thread id - 1; deleted 1 row with t_key = 9216
[NsSampleWork] Thread id - 1 selected 1 row [824,Derby26 ,8.802546E22,9155]
[NsSampleWork] Thread id - 1; updated 1 row with t_key = 9155
[NsSampleWork] Thread id - 1; closed connection to the database.
[NsSampleClientThread] Thread id - 1; finished all tasks.
[NsSampleWork] Thread id - 2; updated 0 row with t_key = 9372
[NsSampleWork] Thread id - 2; updated 1 row with t_key = 9155
[NsSampleWork] Thread id - 2 selected 1 row [56,Derby26 ,8.802546E22,9155]
[NsSampleWork] Thread id - 2; inserted 1 row.
[NsSampleWork] Thread id - 2; updated 1 row with t_key = 9155
[NsSampleWork] Thread id - 2; deleted 1 row with t_key = 9155
[NsSampleWork] Thread id - 2 selected 1 row [785,Derby2 ,0.30170244,8280]
[NsSampleWork] Thread id - 2 selected 1 row [785,Derby2 ,0.30170244,8280]
[NsSampleWork] Thread id - 2; updated 1 row with t_key = 8280
[NsSampleWork] Thread id - 2 selected 1 row [59,Derby2 ,0.30170244,8280]
[NsSampleWork] Thread id - 2; closed connection to the database.
[NsSampleClientThread] Thread id - 2; finished all tasks.
[NsSample] Shutting down network server.
Apache Derby Network Server - shutdown
[NsSample] End of Network server demo.

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