Jack
Jack

Reputation: 140

write to sqlite db packaged inside a jar

I'm trying to use a DB for reading and writing that is contained in a JAR. I can read in it, but can't write throwed exeception :

java.sql.SQLException: path to '/database/scddata.db': 'LocationOfJar/database' does not exist

Is there any way I can bundle the database file inside a JAR?

Thanks in advance.

Upvotes: 2

Views: 585

Answers (1)

jeorfevre
jeorfevre

Reputation: 2316

Jar files does not allows to write.

So :

  1. define a working path (in properties for example). Let's call it : workingPath/file.db.

  2. on init of your program, before opening your db.

    • check if db exists in working path
    • if does not exists : copy your jar file.db file to workingPath/file.db .
  3. Then you program will use the db from workingPath/file.db for execution.

Upvotes: 4

Related Questions