Running the Derby Client Demo
To run the java SimpleNetworkClientSample.java program, open a DOS console and change the directory to the nserverdemo folder. As for the server, on my installation this is contained in the following path:
C:\java\db-derby-10.1.2.1-bin\demo\nserverdemo
When you're in this directory, type the following commands:
javac SimpleNetworkClientSample.java java SimpleNetworkClientSample
And, if all is well, you should see something like that illustrated in Listing 2.
Listing 2 Client Program Output
Starting Sample client program Got a client connection via the DriverManager. connection from datasource; getDriverName = Apache Derby Network Client JDBC Driver Got a client connection via a DataSource. Testing the connection obtained via DriverManager by executing a sample query Please press Enter to test the Derby connection.
Notice the pleasant lack of Java exceptions in Listings 1 and 2! This is an indication that your setup has been successful and also that you've managed to get the client and server up and running. So, if you've got this far without incident, well done!
You're now running a separate client JVM to connect to a Derby database server in another JVM. This is the very opposite of running Derby in embedded mode. If you're feeling adventurous, you could also run the two programs (i.e., client and server) on separate machines connected by a network.
The last line of Listing 2 illustrates that the client is waiting for you to press <Enter> before testing the database connection. So, what happens when you press <Enter>? To find out, have a look at Listing 3.
Listing 3 Testing the Remote Derby Connection
number of rows in sys.systables = 16 Testing the connection obtained via a DataSource by executing a sample query number of rows in sys.systables = 16 Goodbye!
Nothing too dramatic there, but what you're seeing is the result of a SQL query on the remote database. In spite of its simplicity, this is actually pretty powerful stuff given the tiny amount of source code and configuration involved. Installing and running some commercial database management system products is often far and away more difficult.