This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JDBC and the fly likes How to achieve Connection polling in JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "How to achieve Connection polling in JDBC" Watch "How to achieve Connection polling in JDBC" New topic
Author

How to achieve Connection polling in JDBC

Anand Bhatt
Ranch Hand

Joined: May 30, 2007
Posts: 187
In my app code i am, for each and every method i am taking a Jdbc Connection( defined as a singleton class) using it and at the end of every method i am closing it.
Overall there is lots og conection opening and closing in that file. How can i get rid ofthis frequent opening and closing of connection.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3652

Don't reinvent the wheel. Most application servers provide a mechanism for creating and managing connection pools. In such a scenario, you then request a connection from the data store and it will give you one if its open. Check the documentation for whatever application server you are using to see how to establish connection pools.


My Blog: Down Home Country Coding with Scott Selikoff
Meet Gaurav
Ranch Hand

Joined: Oct 08, 2008
Posts: 492
Scott,

Could you please tell me if the application is POJO (simple java class). We can't use application server datasource. In this case how to make use of Connection and data source.

As of my knowledge we can achieve this by Apache commons rite
by using
1. commons-dbcp.jar
2. commons-pooljar
3. commons-collections.jar

Is their any other alternative for connection pool and datasource usage in standalone Java application.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to achieve Connection polling in JDBC
 
Similar Threads
How to use Connection Pooling?
Methods for using JDBC Class in a web app?
method with SQL parameter
How to handle db connections in servlets?
How to use Connection Pooling?