• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use Connection Pooling?

 
Girish Bapat
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am opening and closing connection for my each method in database bean.
I have 2 questions
Does this practice create performance problem?
If yes
Can someone tell me how to use connection pooling
Thanks in Advance,
- Girish
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should always close a connection as soon as your are finished with it - ignoring performance implications. And you should do the same even if you use connection pooling (though in this instance the connection is actually returned to the pool rather than closed).

Your code shouldn't change if you use connection pooling or not (assuming you are using a DataSource). Where are you getting your connection pooling implementation from?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How you implement one depends on what JDBC driver you are using. Some have it built in. What container you are using. Tomcat (and most other) containers has a container managed connection pool. You can also implement one yourself.
There is good opensource implimentation here:
http://jakarta.apache.org/commons/dbcp/

Check the documentation for your driver and servlet container.
If you followed Paul's advice, you may already be using it.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your question is off topic for this forum.

This forum is for Servlets questions.

I am going to move this thread to the more appropriate, JDBC forum

Thanks and good luck

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic