HSQLDB and Java

HSQLDB is .. well, not what I was expecting. The database as it sits on the HD is essentially just a script file that gets read during the DB engine startup. All the data is completely in plain text it looks like. But for my purpose I suppose that is just fine.

Used this as starting place: http://www.hsqldb.org/doc/1.8/guide/apb.html

** Note remove the "package" line from the class in that example and the "main class" will be found.

In linux, with the compiled class file, hsqldb.jar, sqltools.jar all in the same directory I needed to set the class path like:


export CLASSPATH=hsqldb.jar:./

Then running "java Testdb" produces output:
[xavier@alice lib]$ java Testdb
0 Ford 100
1 Toyota 200
4 Ford 100
5 Toyota 200
8 Ford 100
9 Toyota 200
12 Ford 100
13 Toyota 200
16 Ford 100
17 Toyota 200
The cool part is that the sqltools.jar works just like a oracle or mysql command line interface:
java -jar sqltool.jar --inlineRc=url=jdbc:hsqldb:file:db_file,user=sa
and off you have an interactive interface to run SQL commands at.
==== update =====
Thought I would also document quickly that to get it to work in Netbeans, the only place I had to add the library to the project to was the "compile" tab.
- Right click on your active project
- Go to Properties
- Select the library option
- select the compile tab
- Click "Add Library.."
- Select the HSQLDB.jar file (which should be in your project already somewhere.)
This will create the database files at the base of your project directory.


© 2017 Chad Jorgenson. All Rights Reserved.