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 or 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 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 [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
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] Begin creating table - SAMPLETBL and necessary indexes.
[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://localhost:1621/NSSampledb;create=true;
Connection number: 3.
[NsSampleWork] Thread id - 1 selected 1 row [998,Derby41 ,2.92903314E14,9572]
[NsSampleWork] Thread id - 2 selected 1 row [998,Derby41 ,2.92903314E14,9572]
[NsSampleWork] Thread id - 1 selected 1 row [998,Derby41 ,2.92903314E14,9572]
[NsSampleWork] Thread id - 1 selected 1 row [998,Derby41 ,2.92903314E14,9572]
[NsSampleWork] Thread id - 1 selected 1 row [998,Derby41 ,2.92903314E14,9572]
[NsSampleWork] Thread id - 1; inserted 1 row.
[NsSampleWork] Thread id - 1 selected 1 row [998,Derby41 ,2.92903314E14,9572]
[NsSampleWork] Thread id - 1 selected 1 row [52,Derby41 ,2.92903314E14,9572]
[NsSampleWork] Thread id - 1 selected 1 row [52,Derby41 ,2.92903314E14,9572]
[NsSampleWork] Thread id - 2; updated 1 row with t_key = 9572
[NsSampleWork] Thread id - 1; updated 1 row with t_key = 9572
[NsSampleWork] Thread id - 2 selected 1 row [53,Derby41 ,2.92903314E14,9572]
[NsSampleWork] Thread id - 1; inserted 1 row.
[NsSampleWork] Thread id - 1; closed connection to the database.
[NsSampleClientThread] Thread id - 1; finished all tasks.
[NsSampleWork] Thread id - 2; deleted 1 row with t_key = 9572
[NsSampleWork] Thread id - 2 selected 1 row [923,Derby14 ,4122.9033,9180]
[NsSampleWork] Thread id - 2; inserted 1 row.
[NsSampleWork] Thread id - 2 selected 1 row [923,Derby14 ,4122.9033,9180]
[NsSampleWork] Thread id - 2; inserted 1 row.
[NsSampleWork] Thread id - 2 selected 1 row [923,Derby14 ,4122.9033,9180]
[NsSampleWork] Thread id - 2 selected 1 row [923,Derby14 ,4122.9033,9180]
[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: