How to include SQLite database in executable Jar?

What library are you using for SQLite?

I did a search based on the connection URI you indicated and found this one. In the documentation it says:

2009 May 19th: sqlite-jdbc-3.6.14.1 released. This version supports “jdbc:sqlite::resource:” syntax to access read-only DB files contained in JAR archives, or external resources specified via URL, local files address etc. (see also the detailes)

If that is the driver you are using, then I would suggest the following connection URI:

"jdbc:sqlite::resource:DatabaseFile"

The key is that since your database is in a jar file, it can not be access as a file with FileInputStream. Instead it must be accessed through the JVM’s support for it (namely with Class.getResource() or Class.getResourceAsStream()). Do note that resources contained within jar files are read-only. You won’t be able to save any changes to your database.

Leave a Comment