SOCKET
Running in the Derby
The Derby database, of course. Going on general reports, recommendations from a colleague, and mutterings from my Auntie Fanny, the decision has been made to use Apache Derby as the back end for the jUDDI registry. The most obvious advantage is ease of deployment and portability. The whole of SOCKET can be wrapped up in a WAR with the derby.jar file nicely stowed away inside.
Derby is ridiculously straightforward to crank up, especially with the aid of the book, Apache Derby - Off to the Races - Includes Details of IBM Cloudscape, by Paul C. Zikopoulos, Dan Scott and George Baklarz out of IBM Press, Pearson (2006). This book is a real pleasure to fondle. Beautiful crisp, black, blue and white IBM theme with a blurred hossie on the front. A sturdy hardback, well laid out and good quality paper.
I provide below some jottings on how to start experimenting with the database under Java on Windows XP.
Get the latest stable release from http://db.apache.org/derby/derby_downloads.html. This is presently 10.1.2.1. The lib download is fine: db-derby-10.1.2.1-lib.zip.
Unzipping this download reveals a few derby jars plus some internationalization jars. For the moment, the two important ones here are derby.jar and derbytools.jar. derby.jar contains the database files while derbytools.jar has inside it 'ij', the Apache Derby JDBC scripting tool, using which you can execute SQL scripts against Derby databases.
Add these two files to your Java classpath by first opening the My Computer window, right-clicking and selecting Properties to summon the System Properties window. Select the Advanced tab and then the Environment Variables button. Make a new user variable called CLASSPATH. My value for this was
D:/derby/db-derby-10.1.2.1-lib/lib/derbytools.jar;D:/derby/db-derby-10.1.2.1-lib/lib/derby.jar
If there are already entries in the CLASSPATH variable, just tack these two soldiers on the end with semi-colon separators.
Now you can use the ij tool to create a database as shown below.
There is now a directory D:/JUDDI containing the Derby files for the JUDDI database. You can add a path to the directory when you create it.
Add dataEncryption=true;bootPassword=myBootPassword to encrypt the newly created database. In this case the bootPassword property of the connection object must be set to myBootPassword to gain access.
Now you can write a little Java program to access the database:
package derbytest;
import java.sql.*;
import javax.sql.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
public class DerbyCranker {
public DerbyCranker() {
}
public static void main(String[] args) {
DerbyCranker derbyCranker1 = new DerbyCranker();
String DerbyDriver = "org.apache.derby.jdbc.EmbeddedDriver";
try {
Class.forName(DerbyDriver).newInstance();
System.out.println("Driver located and loaded.");
}
catch (Exception NoDriver) {
System.out.println("No driver: " + DerbyDriver);
System.exit(1);
}
String url = "jdbc:derby:D:/JUDDI";
Properties properties = new Properties();
properties.put("retrieveMessagesFromServerOnGetMessage", "true");
try {
Connection conn = DriverManager.getConnection(url, properties);
.
.
.
conn.close();
}
catch (SQLException se) {
String SQLState = se.getSQLState();
String SQLMessage = se.getMessage();
System.out.println("Error: " + SQLState);
System.out.println(SQLMessage);
}
}
}
Hours of fun.
Posted at 05:06PM May 19, 2006 by Brian Peter Clark in Misc technical |