background image
<< java org.apache.derby.tools.sysinfo | Running the SimpleNetworkClientSample program >>

Network Server sample programs

<< java org.apache.derby.tools.sysinfo | Running the SimpleNetworkClientSample program >>
Derby Server and Administration Guide
56
Connection number: 4.
Shutdown successful.
Running the NsSample program also creates the following new directories and files:
NSSampledb
This directory makes up the NSSampledb database.
derby.log
This log file contains Derby progress and error messages.
Network Server sample programs for embedded and client connections
This Derby Network Server sample program demonstrates how to obtain an embedded
connection and client connections to the same database by using the Network Server.
This program shows how to use either the DriverManager or a DataSource to obtain
client connections.
For a database to be consistent, only one JVM can access it at a time. The embedded
driver is loaded when the Network Server is started. The JVM that starts the Network
Server can obtain an embedded connection to the same database that the Network
Server is accessing to serve clients from other JVMs. This solution provides the
performance benefits of the embedded driver and also allows client connections from
other JVMs to connect to the same database.
Overview of the SimpleNetworkServerSample program
The SimpleNetworkServerSample program starts the Derby Network Server, as well
as the embedded driver, and waits for clients to connect. The program performs the
following tasks.
· Starts the Derby Network Server by using a property and also loads the embedded
driver
· Determines if the Network Server is running
· Creates the NSSimpleDB database if it is not already created
· Obtains an embedded database connection
· Tests the database connection by executing a sample query
· Allows client connections to connect to the server until you decide to stop the server
and exit the program
· Closes the connection
· Shuts down the Network Server before exiting the program
To run the sample program, install the following files in the
%DERBY_HOME%\demo\nserverdemo\
directory:
· The source file:
SimpleNetworkServerSample.java
· The compiled class file:
SimpleNetworkServerSample.class
Running the SimpleNetworkServerSample program
To run the Derby Network Server sample program:
1. Open a command prompt and change directories to the
%DERBY_HOME%\demo\nserverdemo directory, where %DERBY_HOME% is the
directory where you installed Derby.
2. Set the classpath to include the current directory ("."), and the following jar files:
derbynet.jar
The Network Server jar file. It must be in your CLASSPATH because you start the
Network Server in this program.
derby.jar
The database engine jar file.
derbytools.jar
The Derby tools jar file.
3. Test the CLASSPATH settings by running the following Java command: