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.
Hey all! I have implemented my own Front Controller solution and it's now time to deal with database connectivity. I have read about some different solutions. First of all a basic questions:
Question 1: How does Driver.getConnection() work? Does it return a new connection everytime it's invoked?
Solution: The Front Controller servlet invokes the the Driver.getConnection method in its init() method, and closes it in its destroy() method. The connection is then passed to my Action/Command objects.
Question 2: Does this mean that I only have one database connection for my web-app?
Is this a good solution? I have also read about having something called a BaseDao which is extended by other conrecte Daos' such as UserDao, NewsDao etc. This concrete classes invokes the super method getConnection, does it mean that I will get a new connection for every call?
I'm very confused about how to deal with the connections... [ October 12, 2006: Message edited by: Joel Hutters ]
Have you considered database pooling? This is where you define a database connection on a server and then request a connection from within the application. The trick here is that your connection might come from any one of N database connections all ready available in the pool. The other trick when using database pooling is to make sure to close connections after you use them or you will use up the pool quickly.