My suggestion is not to re invent the wheel again. The are lots of Open source APIs available. If you are curious about how it is implemented, download the source code of any of those and do reverse engineering.
There are a number of connection pooling scripts that create vectors, shove connections into that vector, and manage that vector depending upon lifespan and utilization. Unfortunately, alot of those scripts tend to waste resources over the long term.
Because 'custom' connection pools have been so historically unreliable, pretty much every framework, from Struts to Cocoon, and app server, from JBoss to WebSphere, have their own connection pooling implementation. It is best to piggy-back off of those implementations.
What framework/app server are you using?
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay:
a bit of art, as a gift, that will fit in a stocking