| Author |
Confused about how to handle conncetion
|
Joel Hutters
Greenhorn
Joined: Sep 07, 2006
Posts: 21
|
|
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 ]
|
 |
Scott Selikoff
Saloon Keeper
Joined: Oct 23, 2005
Posts: 3652
|
|
|
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.
|
My Blog: Down Home Country Coding with Scott Selikoff
|
 |
Joel Hutters
Greenhorn
Joined: Sep 07, 2006
Posts: 21
|
|
Yeah  I actually implemented a connection pool solution with the built in support dbcp in apache. Works great together with mySQL
|
 |
 |
|
|
subject: Confused about how to handle conncetion
|
|
|