This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I am trying to deploy a same piece of code on different Tomcat environment with different serverport. Each environment should connect to different database connection. What is a common approach to make the code itself be able to sense the difference in serverport connection and connect itself to the appropiate db?
also, would any framework (ex. struts, hibernate) help to make it convenient at all?
A common approach is to not do that, but to configure the appropriate database connection information in each instance of Tomcat. Then your code just uses JNDI to get a connection and it's automatically connected to the right place.
Thanks a lot for the inputs. The environment are associated with different boxes. I think the JNDI solution sounds great. I am now looking into some info about configuring Tomcat with db and using JNDI lookup in the code. It would be great if anyone has some useful resources/links that can send me.
Joined: Jul 09, 2008
I have recently tried to make use of JNDI to connect to database and it works awesome, thanks. But I have one slight problem, if I put JNDI resources under webapp/META-INF/context.xml, then it will work; but if I put it under TOMCATROOT/conf/context.xml, then it won't work. I really want it to be in the server/JVM scope so that I don't have to recreate the context resource for every single web app I have. How can I do that?