Tuesday, May 24, 2011

HyperSonic/HyperSQL Quickstart

HyperSQL is a fantastic tool for local rapid development and testing. A lot of people don't seem to know about it, or just how useful it is. Some advantages:
  1. You do not need to install it, so you do not need local admin rights (a hurdle in corporate environments).
  2. It saves everything in a readable, and editable text file. In other words, the database IS the text file (see below for example).
  3. It starts up in no time (an empty DB for me starts up in 385 ms!).
  4. It is fully JDBC compatible.
As a quick start (based on release 2.2.2, which is the latest as of this post):
  • Download the latest HyperSQL/HSQLDB zip file
  • extract it to your local drive, in this example C:\bin\hsql
  • cd C:\bin\hsqldb-2.2.2\hsqldb\bin
  • make a new batch file, call it say hsqlStart.bat
  • edit the batch file, and put this in it:
  • java -cp ../lib/hsqldb.jar org.hsqldb.server.Server --database.0 file:C:\bin\hsqldb-2.2.2\hsqldb\data\myDb --dbname.0 test
  • Run the batch file from the comman prompt from the bin folder
  • Connect to the database using the jdbc compatible SQL editor of your choice, using the connection string: jdbc:hsqldb:hsql://localhost/test", "SA", "", and the driver found at: C:\bin\hsqldb-2.2.2\hsqldb\lib\hsqldb.jar
  • Refer to the HyperSQL/HSQLDB User Guide for anything not covered by this quick start.

As mentioned it saves all updates in a plain text file. So if you run:
    create table my_tbl(
    my_key INT primary key,
    some_text VARCHAR(256)
    )
and then open the file: C:\bin\hsqldb-2.2.2\hsqldb\data\temp.log, you will see it has the create table directly in there. This is VERY useful for troubleshooting and sanity checks during rapid development.

To shutdown the server cleanly type 'SHUTDOWN' in your SQL editor (such as Squiral SQL). You will notice it shutdown, and copies the data cleanly from the temp.log file into temp.script. This file is actually editable, so you can edit the SQL driectly in the script file, cool huh?

Hope this is useful for someone, shout out if it is!

No comments: