Setting up a JSP site pre-database
I am working on a website in JSP (in GWT really, but on the server side it is really just JSP) and I need to set up my database.
I know how to write code in connection with a database, etc., but I am wondering how / where to save the database configuration.
To clear up my doubts, let me give you an example; in PHP, a normal website has config.php where the user configures the database, user, etc. (or creates setup.php).
However, since the JSP is bytecode, I cannot encode this information on my site and change it by the user, nor can I change it like install.php.
How can I do it? what's the best / most common practice? I found NO examples of this. Basically where should the config file be stored?
a source to share
There are several possibilities to do this, what I've seen includes:
- The presence of database credentials in a special file, usually
db.properties
or some simple XML file, which contains the required information (driver, url, username, password, any ORM parameters, if necessary). The properties file will be placed underWEB-INF
orWEB-INF/classes
; The downside to this approach is that the user will have to modify the file inside the WAR before deploying it to the application server. - Purchase a database connection via JNDI and expect it to be provided by the application server. This is probably the most common way to do it; on the other hand, your WAR does not need to be changed, however the downside is that the JNDI datasource setup is different for each application server and can be confusing if your sysadmins are new to Java technology.
a source to share