Code Search for Developers
 
 
  

simpleserversample.html from CSDerby at Krugle


Show simpleserversample.html syntax highlighted

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Derby Network Server Simple sample program</title>
</head>

<body>

<h2>Simple Derby Network Server Example</h2>

<h2>Overview</h2>

<p>The primary purpose of this example is to demonstrate how to obtain an embedded
connection and client connections using the Network Server to the same
database. This program shows how to use either the DriverManager or a
DataSource to obtain client connections. </p>

<p>In order for a database to be consistent, only one JVM is allowed to access
it at a time. The embedded driver is loaded when the Network Server is started.
Hence, the JVM that starts the Network Server can get an embedded connection to
the same database that Network Server is accessing to serve the clients from
other JVMs. This solution allows you to take advantage of the performance
benefits of the embedded driver as well as allow for client connections from other
JVMs to connect to the same database.</p>

<p>In this example, the following two programs show how to setup the server and
client programs when interacting with the Network Server.</p>

<p>SimpleNetworkServerSample.java:
This program starts the Derby Network Server as well as the embedded
driver and waits for clients to connect.</p>

<p>SimpleNetworkClientSample.java:
This is the client program that interacts with the Derby Network Server
from another JVM.</p>

<h3>SimpleNetworkServerSample program</h3>

<p>In particular, this program:</p>

<ul>
 <li>starts the Derby Network Server using a property and also loads the embedded driver</li>
 <li>checks if the Derby Network Server is up and running</li>
 <li>creates the database 'NSSimpleDB' if not already created </li>
 <li>obtains an embedded database connection</li>
 <li>tests the database connection by executing a sample query</li>
 <li>allows for client connections to connect to the server until the user decides to stop the server and exit the program</li>
 <li>closes the connection</li>
 <li>shuts down the Derby
     Network Server before exiting the program.</li>
</ul>

<p>The following files should be installed in the <font style=italic>%DERBY_INSTALL%</font><tt><span>\demo\programs\nserverdemo\</span></tt> directory in
order to run this sample program:</p>

<ul>
 <li> Source file:</li>
 <ul>
  <li><tt>SimpleNetworkServerSample.java</tt></li>
 </ul>
 <li>Compiled class file:</li>
 <ul>
  <li><tt>SimpleNetworkServerSample.class</tt></li>
 </ul>
</ul>

<h2>How to run the SimpleNetworkServerSample program</h2>

<p>To run this simple Derby Network Server sample program:</p>

<ol>
 <li>Open a command prompt and change directories to the <span class=italic>%DERBY_INSTALL%</span>\demo\programs\nserverdemo
     directory, where <span class=italic>%DERBY_INSTALL%</span> is the directory
     where you installed Derby.</li>
 <li>Set the CLASSPATH to include the following jar files in order to run this
     program.</li>
<ul><li>the current directory (".")</li>
<li><tt>derbynet.jar</tt>: <BR>The Network Server jar file. It must be in your CLASSPATH since we start the Network Server in this program.</li>
<li><tt>derby.jar</tt>: <BR>The Derby database engine jar file.</li>
</ul>

<li>Test the CLASSPATH settings by running the following java command:

<pre>java org.apache.derby.tools.sysinfo</pre>

<p>This command will show the Derby jar files that are in the CLASSPATH. </p></li>

<li>Once you have set up your environment correctly, execute the application from the <br><span class=italic>%DERBY_INSTALL%</span>\demo\programs\nserverdemo directory:

<pre>java SimpleNetworkServerSample</pre>
</li></ol>
<p>You should receive output similar to the following if the program runs successfully:</p>

<tt>
Starting Network Server<br>
Testing if Network Server is up and running!<br>
Derby Network Server now running<br>
Got an embedded connection.<br>
Testing embedded connection by executing a sample query <br>
number of rows in sys.systables = 16<br>
<br>
While my app is busy with embedded work, ij might connect like this:<br>
<br>
        $ java -Dij.user=me -Dij.password=pw -Dij.protocol=jdbc:derby://localhost:1527/ org.apache.derby.tools.ij<br>
        ij> connect 'NSSimpleDB';<br>
<br>
<br>
Clients can continue to connect: <br>
Press [Enter] to stop Server<br>
</tt>

<p>Running this program will also create new directories and files:</p>

<ul>
 <li><span>NSSimpleDB</span><br>
This directory makes up the <span>NSSimpleDB</span> database.
</li>
<li><tt>derby.log</tt><br>
This log file contains Derby progress and error messages.
</li></ul>


<h2>Example of a Client connecting to the Network Server</h2>

<h3>SimpleNetworkClientSample program</h3>

<p>This program:</p>

<ul>
 <li>loads the DB2 JDBC Universal Driver or the Derby Network Client JDBC Driver</li>
 <li>obtains a client connection using the Driver Manager</li>
 <li>obtains a client connection using a DataSource</li>
 <li>tests the database connections by executing a sample query</li>
 <li>closes the connections and then exits the program.</li>
</ul>

<p>The following files should be installed in the <span class=italic>%DERBY_INSTALL%</span><tt>\demo\programs\nserverdemo\</tt> directory in order to run this sample program:</p>
<ul>
 <li>Source file: <br><tt>SimpleNetworkClientSample.java</tt></li>
 <li>Compiled class file: <br><tt>SimpleNetworkClientSample.class</tt></li>
</ul>

<h2>How to run the SimpleNetworkClientSample program</h2>

<p>To connect to the Network Server that has been started as part of the SimpleNetworkServerSample program:</p>

<ol>
 <li>Open a command prompt and change directories to the <span class=italic>%DERBY_INSTALL%</span><tt>\demo\programs\nserverdemo</tt> directory, where <span class=italic>%DERBY_INSTALL%</span> is the directory where you installed Derby.</li>
 <li>Clients of Derby Network Server only need the following jar files in the CLASSPATH in order to connect to the Network Server.<span>  </span>Set the CLASSPATH to include the following jar files:
 <ul>
  <li>the current directory (".")</li>
<li><tt>derbyclient.jar</tt><br>This jar file must be in your CLASSPATH to use t
he Derby Client Network JDBC Driver.</li>
  <li><tt>db2jcc.jar</tt><br>This jar file must be in your CLASSPATH to use the DB2 JDBC Universal Driver.</li>
  <li><tt>db2jcc_license_c.jar</tt><br>This jar file is the license file for the Universal Driver for Derby.</li>
 </ul></li>
<li>Once you have set up your environment correctly, execute the
application from the <br><span class=italic>%DERBY_INSTALL%</span><tt>\demo\programs\nserverdemo\</tt> directory:
<pre><tt>java SimpleNetworkClientSample [driverType]</tt></pre>
<ul>
<li>Where the possible values for driverType are:
<ul>
<li>derbyClient (default)
<li>jccjdbcclient
</ul>
</ul>
</li>
</ol>

<p>You should receive output similar to the following if the program runs
successfully:</p>

<tt>
Starting Sample client program <br>
Got a client connection via the DriverManager.<br>
connection from datasource; getDriverName = Apache Derby Network Client JDBC Driver<br>
Got a client connection via a DataSource.<br>
Testing the connection obtained via DriverManager by executing a sample query <br>
number of rows in sys.systables = 16<br>
Testing the connection obtained via a DataSource by executing a sample query <br>
number of rows in sys.systables = 16<br>
Goodbye!<br>
</tt>

</body>

</html>




See more files for this project here

CSDerby

CSDerby is not CloudScape-Derby(for Java) but rather Derby forked/ported to CSharp. Specifically it is intended to be a native c# Embedded DB for the mono/net platform with the ADO.NET API instead of the JDBC API.

Project homepage: http://sourceforge.net/projects/csharpderbyport
Programming language(s): Java,SQL
License: apache20

  NetworkServerUtil.java
  NsSample.java
  NsSampleClientThread.java
  SimpleNetworkClientSample.java
  SimpleNetworkServerSample.java
  nserverdemo.html
  readme.html
  simpleserversample.html