开发者

which is the best way to externalize a database configuration on a desktop app?

I'm working in a desktop app, and we're using Eclipse RCP with Ec开发者_Go百科lipseLink.

All my database configuration is inside a class, but I'll need these thing (database URL, password, username) configurable.

Which is the best way to do that?


The standard way is to have a properties (either java.util.Properties or XML) file in which is stored the database details. This can be writeable by the user of course, and passwords stored in such a file need to be encrypted.

It's a nice idea to give the user a means of setting these from the application rather than having to edit the file manually though.


In addition to the answers already given I would suggest externalizing the reference to the properties file by specifying it as a command-line option, e.g:

java my.app.MainClass -Ddb.config=/path/to/db.properties

You can then grab the path like so:

final String dbConfigPath = System.getProperty("db.config");


Easiest way would be to use some simple property file and java.util.Properties to read it.

You can read the file from classpath, e.g:

Class.getResourceAsStream ("resource.properties");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜