• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confused about how to handle conncetion

 
Joel Hutters
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Saloon Keeper
Posts: 4014
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joel Hutters
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah
I actually implemented a connection pool solution with the built in support dbcp in apache. Works great together with mySQL
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic