File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC 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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Accessing an HSQL file-based database inside a .jar" Watch "Accessing an HSQL file-based database inside a .jar" New topic
Author

Accessing an HSQL file-based database inside a .jar

Kurt Kopf
Greenhorn

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:
http://hsqldb.org/doc/2.0/guide/running-chapt.html#running_inprocess-sect
http://hsqldb.org/doc/src/org/hsqldb/jdbc/jdbcConnection.html
http://download.oracle.com/javase/6/docs/api/java/lang/Class.html#getResourceAsStream(java.lang.String)

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
Greenhorn

Joined: Jun 28, 2010
Posts: 9
Found some info in this thread:
http://sourceforge.net/projects/hsqldb/forums/forum/73674/topic/1481509

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 db.properties (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
Bartender

Joined: Dec 20, 2006
Posts: 2476
    
    7

Thank you for posting the solution, Kurt.


OCUP UML fundamental and ITIL foundation
youtube channel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing an HSQL file-based database inside a .jar
 
Similar Threads
Same old problem?
Which embadded database is good for application
Simple Database
Unable to access a file in my Jar file.
sqlexception with hsqldb-please help