How to use SQLite database inside jar file?

aljabear picture aljabear · Jun 27, 2011 · Viewed 9.2k times · Source

I can't figure out how to include a SQLite database within a Java .jar file for deployment (via Java WebStart).

The database does not need to be updated at runtime... it is essentially a glorified configuration file.

Using Eclipse, by the way.

Answer

user166390 picture user166390 · Jun 28, 2011

SQLite requires the separate files because of how the engine ensures locking and ACID. Even without the need to update the database, SQLite is only designed to work with direct file access (or memory backing, but not one supplied from Java or another host ;-) - SQLite is showing it's not a pure Java solution here nor is it designed for systems not utilizing the basic system IO subsystem(s).

The SQLite data files could be extracted from the JAR to a temporary location at start (and put back in there at the end, if needed) - but other than something similar to this approach, not possible. The task itself isn't complicated, but is another thing that needs to be done and may require additional privileges not available in some environments.

Happy coding.