HSQLDB - hiding database structure/contents from users

2009-08-24 java hsqldb

I'm considering using HSQLDB version 1.8.x in a desktop app for storing local data. From what I can see, the database is stored on disk as a number of SQL statements to create the tables, insert the data, etc.

Is there a simple way I can hide this from users? I'm don't necessarily need it to be completely encrypted, etc - I'd just like to prevent the casual user from simply opening the file and seeing the structure of the database.

Answers

You could embed your database files within a jar file and connect to them using the notation:

jdbc:hsqldb:res:<path in jar>

Check out the Advanced Topics section of the HSQLDB guide for more information on this. However, I've never tried it so am not 100% sure it will work ...

The solution I've gone with for now is to call:

db.update("SET SCRIPTFORMAT COMPRESSED;");

to store the .script file in a human-unreadable form and:

db.update("SET PASSWORD password;");

to prevent more savvy users from opening the DB using their own HSQLDB client.

Unfortunately I was not able to execute below command
db.update("SET scriptformat COMPRESSED");

And was getting this error

java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: SCRIPTFORMAT

This error solved with this command
db.update("SET FILES SCRIPT FORMAT COMPRESSED");

I am using HSQLDB 2.3.3

Related