Starting JavaDB (Derby) Network Server From Java Application

Generally for beginners making a project find it difficult to understand how to start the Java DB network server or shut it down right from their java code.

There are two ways to do this as described in Derby documentation (http://db.apache.org/derby/docs/dev/adminguide/tadminconfig814963.html):

  1. You can use the NetworkServerControl API to start the Network Server from a separate thread within a Java application:.
  2. Using a derby.properties file with some special strings inside it.

For the beginners I suggest to go with the first method of using the NetworkServerControl API and I am going to explain the same for you. For second method you can look in documentation on the link given above.

NetworkServerControl class is included in the JavaDB(Apache Derby) package.  It is located in lib\derbynet.jar\org\apache\derby\drda\NetworkServerControl.class

So derbynet.jar must be in your classpath or included in your project libraries. It contains four constructors that let you start derby server in a more flexible way. Here is a small guide in documentation of Apache derby on these four constructors (http://db.apache.org/derby/docs/10.7/adminguide/tadminconfig813694.html)

You can find the NetworkServerControl API information on http://download.oracle.com/javadb/10.4.2.1/javadoc/jdbc3/org/apache/derby/drda/NetworkServerControl.html

You can use any of the below to start the server on the local host machine and if you want to start the server on a different host then you can insert the InetAddress.

NetworkServerControl serverControl=new NetworkServerControl();
serverControl.start(new PrintWriter(System.out,true));
NetworkServerControl serverControl=new NetworkServerControl(InetAddress.getByName("localhost"),1527);
serverControl.start(new PrintWriter(System.out,true));
Advertisements

, , , , ,

  1. #1 by Long on August 8, 2011 - 11:58 PM

    Thanks for the tutorial. It was very clean, clear and simple. The links you provided were very helpful and relevant as well. I was just looking up this very info and I am sure others will find it just as helpful as I did.

  2. #2 by CostaF. on March 2, 2012 - 5:12 PM

    Thanks for this code, it solve my needs in corrent application.

  3. #3 by hari on December 29, 2012 - 10:58 AM

    what package should import and which jar’s should I include for this, and how?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: