views:

184

answers:

1

I have implemented an Java Swing application that uses an embedded JavaDB database. The database need to be stored somewhere and the database tables need to be created at the first run. What is the preferred way to do these procedures?

Should I always create the database in the local directory, and first check if the database file exist, and if it doesn't exist let the user create the tables (or at least show a message that the tables will be created).

Or should I let the user choose a path? but then I have to save the path somewhere. Should I save the path with Preferences.systemRoot();, and check if that variable is set on startup?

If the user choses a path and save it in the Preferences, can I get any problems with user permissions? or should it be safe wherever the user store the database? Or how do I handle this?

Any other suggestions for this procedure?

+1  A: 

I would let the user choose. That way they can run multiple instances (simultaneously or otherwise). Supplying a sensible default would be a good move.

Store the path using the Preferences API (I would store per-user but that may differ depending on your application), and use the File object to determine if directories exist and/or are permissioned properly.

Brian Agnew