Java Properties - Use to Switch database


I am currently running Resin on my own personal computer as a development environment.  I want a way so that when I put the same files up on my web hosts server, they will connect to the production database instead of a test database.

My current database connection code is stored in a backend factory.  I want to add some way to know which environment I am in (which system I am on), so I can change the jdbc dynamically.

Is this the right way to do this or is there an easier way?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You could use a DataSource which can be set up from a context.xml or the server.xml.

For differentiating between different servers, I think that nothing beats a properties file which contains the host url.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stevedaveAuthor Commented:
Could you give an example of either xml file and how I would setup the DataSource?  And where does the .xml go in the directory structure?
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

stevedaveAuthor Commented:
I used System.getProperties to pull out the user name of the current user.  On my web server, it is always different from my development system.  It works, but I am wondering if this is a good way to do it.  Anyone have any insight?  It was very easy to do.
Disagree, using a Datasource is a valid answer
Yes BUT the Asker found another solution which worked for him. This is PAQ - refund.
stevedaveAuthor Commented:
I did find my own solution, but I don't have a problem with awarding the points to bloodredsun.  I probably should implement his solution, but I am still working out the kinks between my local environment and my webserver's environment.

I will award him points.
thank you :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.