This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Accessing an HSQL file-based database inside a .jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Accessing an HSQL file-based database inside a .jar" Watch "Accessing an HSQL file-based database inside a .jar" New topic

Accessing an HSQL file-based database inside a .jar

Kurt Kopf

Joined: Jun 28, 2010
Posts: 9
I know this can be done, as I've head it alluded to many times: including an embedded read-only hsql db (via files) in a .jar file and accessing it.

This is how I have it set up:

My embedded db jar file contents:

This gets successfully exported into my web app as "db.jar" in WEB-INF/lib/

My question is what is the JDBC url format to access this inside the generated jar file?
According to these sources:

the URL should be:

But that doesn't work, or I wouldn't be posting here

I've tried every variation I could think of:

Plus replacing forward slashes with double backslashes (I'm on a windows 7 system at the moment), and every combination of slashes and dots I can think of. I haven't been able to find the specification for the "file_in_jar" notation mentioned in the HSQLDB documentation.

If I access the files that get compiled into the jar with a URL like this:

then it will work. Obviously this doesn't help me for deploying an application though.

I'm using hsqldb 2.0.0, java 1.6.0, and tomcat 6.

Thanks in advance for any help.
Kurt Kopf

Joined: Jun 28, 2010
Posts: 9
Found some info in this thread:

My database was actually "appDb" in camel-case, and apparently HSQLDB does not support camel-case in resource mode for some reason.

After fixing that, I was getting the following error...

The solution to that was to modify (in the jar source). Somehow the "modified" flag had been set to true. Setting that back to false allowed the database to work. While I was in there, I set "readonly" to true for safety.
Jan Cumps

Joined: Dec 20, 2006
Posts: 2565

Thank you for posting the solution, Kurt.

OCUP UML fundamental and ITIL foundation
I agree. Here's the link:
subject: Accessing an HSQL file-based database inside a .jar
It's not a secret anymore!