lundi 13 avril 2015

What is the best way to store a java desktop application's Sqlite database?

I have a Java app that uses a Sqlite database file to store app's configuration, user's preferences and other parameters. The data is read and write during runtime. Now I have to make an installer for this app (for now, it will run on windows).


I would like to have something similar to IsolateStorage on .Net, so I will have a folder exclusively for my application, with read/file privileges for all users, with no risk of some other application damaging my data, or my application damaging some other app's data.


I found several options to store the Sqlite database file but these are the inconvenients I found (I'm using Windows 7 x64):


using System.getProperty("user.home") or System.getenv("HOMEPATH") : I don't like this location because, as long as this is the folder of user's stuff, user can directly edit or delete the database. I can restore it from a fresh copy from the app's installation folder, but it will reset the app's options and configuration.


using System.getenv("APPDATA") : on windows it points to the Roamming folder, the data must be only in the machine where the application is installed.


using System.getenv("LOCALAPPDATA") : looks like the best solution, but it gives me the local data folder for all applications. I can create a subfolder for my application, but I'm not 100% sure if another application will create a folder with the same name (I can avoid this with a guid-ed generated folder name), and I don't know if a crazy privileges' configuration will avoid my application to write in this location. In my machine it points to "C:\Users\MyUser\AppData\Local".


using System.getenv("PROGRAMPDATA") : The same: I can create a subfolder for my application, and I don't know if a crazy privileges' configuration will avoid my application to write in this location. In my machine it points to "C:\ProgramData".


using System.getProperties(java.class.path) : goes directly to the application's installation folder, this is a no-no.


Where can I store the SQLite database, so the user won't face/generate any trouble after installing my app?


Aucun commentaire:

Enregistrer un commentaire