Need Code to create Connection Pool in java

Need code to create the connection pool in java?

Not sure what the question is but don’t create yet another connection pool, use an existing solution like C3P0, Apache DBCP, Proxool or BoneCP (a new player in that field). I would use C3P0.

How does we make sure that connection pool doesn’t return the same object which is already in use?

Because if a connection has been borrowed from the pool and not returned yet, it’s just not in the pool and can’t be assigned to another client of the pool (resources are removed from the pool until they are returned).

How happens if client closed the connection after taking it out from Connection pool?

The connection a client gets from a pool is not really a java.sql.Connection, it’s a wrapper (a proxy) for a java.sql.Connection that customizes the behavior of some methods. The close() method is one of them and does not close the Connection instance but returns it to the pool.

Leave a Comment