Search code examples
javaeclipsehsqldbexecutable-jar

Is there any way to embed a hsqldb data file inside a executable jar?


I created a Java swing project using hsqldb on Eclipse.

Now I want to generate a executable jar putting everything inside the jar, including the hsqldb data files.

When I used the eclipse wizard to do that I received this message:

java.sql.SQLSyntaxErrorException: user lacks privilege or object no found

My questions are:

  1. Is there any way to embed a hsqldb data file inside a executable jar ?
  2. If the answer is yes, What I am doing wrong ?

Solution

  • Consult the online documentation at http://www.hsqldb.org and read the sections containing information about the 'res' protocol. You should know that database files that are accessed in the JAR files of a Java application are treated in a similar fashion to any other resource and are read only.

    An excerpt:

    Table 12.3. Resource Database URL

    Driver and Protocol: jdbc:hsqldb:res:

    Example: jdbc:hsqldb:res:/adirectory/dbname

    Database files can be loaded from one of the jars specified as part of the Java command the same way as resource files are accessed in Java programs. The /adirectory above stands for a directory in one of the jars.