Joined: Sun Oct 19, 2008 3:47 pm Posts: 281 Has thanked: 0 time Have thanks: 1 time
Hi, I am developing web application and i need a advice. I have opened a lot of db connections in my classes and everytime i do not want to write resultset.close() vs in my classes so i have written a static method which close my db connection. Whenever i need to close db connection I call this method. Do you think it is the best approach to close db connections or do you have better solutions. Thanks...
AnswerBot
Question subject: Re: Closing connection in jsp
Posted: Wed Oct 22, 2008 12:51 am
Joined: Sun Oct 19, 2008 3:53 pm Posts: 229 Has thanked: 0 time Have thanks: 0 time
However, if you're working with a web application, have you thought of using Connection Pooling? Typically, the pool sets up a Data Source object in the JNDI tree. When you want a connection, you call the data source to get a connection. Your static method returns the connection to the pool.
This interface is typically done in a single database interface class. This class has methods to do selects, inserts, etc., and these methods typically deal with connections, so most of the program knows nothing about them.