Søren Lund (slu) wrote,
Søren Lund
slu

  • Mood:

HSQLDB Part 1

I'm in the process of creating a small web site. Mainly for my own amusement.

I'm developing in Java, using JSP's and Servlets. The theme of the web site will be Java Technologies in general, with a focus on web development using Java.

As a back-end database I will be using HSQLDB. It's a small database writting 100% in Java.

I will now describe how I got HSQLDB working.

I'll asume that you have knowledge of Java and SQL, and a Java Development Kit and a servlet container installed. I'm currently using Sun's JDK 1.4.2 and Apache Jakarta Tomcat 5.0.28. Furthermore I'm using Gentoo Linux, so if you're using Windows a few changes are required (I'll try to note them, as I go along).

Start by downloading the latest realease, from SourceForge. The file to look for is called hsqldb_1_7_3_1.zip (posibly with a higher version number).

Unzip the archive. I have all my java related files below one common directory, /usr/java/ (c:\Java\ on Windows).

You now have a directory called hsqldb containing all files related to the database. I like to rename this directory to include the version number, e.g. hsqldb-1.7.3.1.

You should add hsqldb-1.7.3.1/lib/hsqldb.jar to you class path. Also you should copy it to your $CATALINA_HOME/common/lib and restart tomcat. You are now ready to compile/run Java-programs using hsqldb.

Run the manager: hsqldb-1.7.3.1/demo/runManager.sh (on Windows use runManager.bat). Enter the following:
Type: HSQL Database Engine Standalone
Driver: org.hsqldb.jdbcDriver
URL: jdbc:hsqldb:file:/path/to/your/app/demobase

Now create a table and put some data into it (click Execute-button after copying the following to the text field):

CREATE TABLE Bookmarks (title VARCHAR(50), url VARCHAR(255));
INSERT INTO Bookmarks (title, url) VALUES ('Java Technology', 'http://java.sun.com/');
INSERT INTO Bookmarks (title, url) VALUES ('HSQLDB 100% Java Database', 'http://hsqldb.sourceforge.net/');
INSERT INTO Bookmarks (title, url) VALUES ('Apache Jakarta Tomcat', 'http://jakarta.apache.org/tomcat/');
CHECKPOINT


The first four lines are standard SQL. The final line is HSQLDB specific.

You can test that it worked, by executing this:

SELECT * FROM Bookmarks ORDER BY title;

Exit the manager.

You now have four files in /path/to/your/app called demobase.log, demobase.properties and demobase.script (and if you didn't exit the manager, you'll also have a demobase.lck file). These three files describe your database, and can be copied to say a tomcat server.

This is the end of this part. The next part will show you how to write Java programs and servlets using the database.
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your IP address will be recorded 

  • 19 comments