Java DB

Apache Derby

Derby Server and Administration Guide

Derby Getting Started
Derby Reference Manual
Derby Developer's Guide
Derby Performance Tuning
Derby Server and Admin Guide
Derby Tools and Utilities
Derby Server and Admin Guide
-Part one: Derby Server Guide
-Derby in a multi-user environment
-Using the Network Server with preexisting Derby applications
-The Network Server and JVMs
-Installing required jar files and adding them to the classpath
-Starting the Network Server
-Shutting down the Network Server
-Obtaining system information
-Accessing the Network Server by using the network client driver
-Accessing the Network Server by using a DataSource object
-XA and the Network Server
-Using the Derby tools with the Network Server
-Differences between running Derby in embedded mode and using the Network Server
-Setting port numbers
-Managing the Derby Network Server
-Managing the Derby Network Server remotely by using the servlet interface
-Derby Network Server advanced topics
-Derby Network Server sample programs
-Part two: Derby Administration Guide
-Checking database consistency
-Backing up and restoring databases
-Replicating databases
-Logging on a separate device
-Obtaining locking information
-Reclaiming unused space

 

The NsSample sample program

The NsSample demonstration program is a simple JDBC application that interacts with the Network Server.

The NsSample program performs the following tasks:
  • Starts the Network Server.
  • Checks that the Network Server is running.
  • Loads the Network Client driver. (Note that this step is not necessary if you are running the client on JDK 1.6 or higher. In that environment, the network client driver loads automatically.)
  • Creates the NsSampledb database if not already created.
  • Checks to see if the schema is already created, and if not, creates the schema which includes the SAMPLETBL table and corresponding indexes.
  • Connects to the database.
  • Loads the schema by inserting data.
  • Starts client threads to perform database related operations.
  • Has each of the clients perform DML operations (select, insert, delete, update) using JDBC calls. For example, one client thread establishes an embedded connection to perform database operations, while another client thread establishes a client connection to the Network Server to perform database operations.
  • Waits for the client threads to finish the tasks.
  • Shuts down the Network Server at the end of the demonstration.
You must install the following files in the %DERBY_HOME%\demo\nserverdemo\ directory before you can run the sample program:
  • NsSample.java

    This is the entry point into the sample program. The program starts up two client threads. The first client establishes an embedded connection to perform database operations, and the second client establishes a client connection to the Network Server to perform database operations.

    You can change the following constants to modify the sample program:

    NUM_ROWS
    The number of rows that must be initially loaded into the schema.
    ITERATIONS
    The number of iterations for which each client thread does database related work.
    NUM_CLIENT_THREADS
    The number of clients that you want to run the program against.
    NETWORKSERVER_PORT
    The port on which the Network Server is running.
  • NsSampleClientThread.java
    This file contains two Java classes:
    • The NsSampleClientThread class extends Thread and instantiates a NsSampleWork instance.
    • The NsSampleWork class contains everything that is required to perform DML operations using JDBC calls. The doWork method in the NsSampleWork class represents all the work done as part of this sample program.
  • NetworkServerUtil.java

    This file contains helper methods to start the Network Server and to shutdown the server.

The compiled class files for the NsSample program are:
  • NsSample.class
  • NsSampleClientThread.class
  • NsSampleWork.class
  • NetworkServerUtil.class
 

javadb@jdbcurl.com