users@glassfish.java.net

Re: Config and change DB connectivity params run time

From: Bill Kocik <bkocik_at_gmail.com>
Date: Fri, 28 Nov 2008 01:07:32 -0500

A common solution for this is to put such settings in a properties
file - say, db.properties:

driver_class_name=some.driver
db_url=jdbc://whatever
db_username=dbuser
db_password=dbpassword

Set that file somewhere on the classpath (WEB-INF/classes is a common
choice). Then you can load it like this:

         Properties db_props = new Properties();
         db_props.load(this.getClass().getResourceAsStream("/
db.properties"));
        driver_class_name = db_props.getProperty("driver_class_name");
        etc...



On 28 Nov, 2008, at 12:47 AM, glassfish_at_javadesktop.org wrote:

> Hi,
>
> I am creating simple web service that will connect SQL sever
> database with user name and password and execute a stored proc, I am
> using prepareStatement
>
> My question is where I should keep below parameters to make my DB
> connectivity, I wan to access them run time, so that I can change
> the config file to move from test to Prod DB when I need
>
> -------
> DRIVER_CLASS_NAME
> DB_URL
> DB_USERNAME
> DB_PASSWORD
> --------
>
> What is the standard in JEE, like in .NET we know web.config file do
> that where we can put those run time and can access easily
>
> What is the equivalent in JEE, please reply
> [Message sent by forum member 'shafi77' (shafi77)]
>
> http://forums.java.net/jive/thread.jspa?messageID=319083
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>



--
Bill Kocik