NewDTinStackoverflow
NewDTinStackoverflow

Reputation: 543

set up database directory

I am working on a Java Desktop program which upon its installation will designate a default database directory and working directory. Where should I save such information so that the next time the user open the program, the program knows where to look for database and working directory?

Things that come to mind:

  1. store everything in the registry (well, did that in MATLAB version and if there is another way, definitely will not go there).
  2. set up another database attached in the jar file to store everything
  3. Is this a so called persistence problem? What are Java Persistence or Java Data Object? Do they have the way to make it working?
  4. any other suggestions?

Upvotes: 0

Views: 123

Answers (3)

Steve J
Steve J

Reputation: 2674

Your persistent memory is your hard drive, of course, so you need to store data there if you want it to persist from execution to execution. Really, anything goes. You could store the configuration in an XML file -- makes it user-readable outside of the application, which is really nice for debugging, and Java comes with libraries for XML parsing and generation. It would be OS-independent, unlike a registry solution, which is Windows specific. And you could use the XML approach to share information between apps, if that matters. Something to consider.

Update: Preferences are cool! Never saw that one before.

Upvotes: 1

Dave Newton
Dave Newton

Reputation: 160191

The Preferences class was created to store things like... preferences in an OS-neutral fashion.

You could also just specify a directory location manually, through a launcher script, or create a default directory in the user's home, and keep both configuration and DB files there.

Upvotes: 2

John Haager
John Haager

Reputation: 2115

Take a look at the Java Preferences API. It is a standard Java SE mechanism for storing preferences that does so in a platform specific, but application neutral way. Uses the Registry on Windows, Preferences files on OS X, and I believe ~/.files on Unix.

Upvotes: 4

Related Questions