Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c3p0 Connection Checkin

I'm trying to implement a solution with c3p0 for the first time. I understand how to initialize the connection pool and "checkout" a Connection from the pool as follows:

ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass(driverClass);
cpds.setJdbcUrl(url);
cpds.setUser(username);
cpds.setPassword(password);
Connection conn = cpds.getConnection(username, password);

But I am having trouble finding out how to "checkin" an already used Connection to go back into the pool. How would I go about doing this? Is there something that I'm doing wrong here?

like image 242
jtbradle Avatar asked Jan 20 '10 16:01

jtbradle


People also ask

How does c3p0 connection pool work?

c3p0 is a Java library that provides a convenient way for managing database connections. In short, it achieves this by creating a pool of connections. It also effectively handles the cleanup of Statements and ResultSets after use.

What are checked out connections?

Check-out means getting a connection from the pool. Check-in means giving back a connection to the pool. Check-out means getting a connection from the pool..

What is c3p0 Hibernate connection pooling?

C3p0 is an open-source JDBC connection pooling library, with support for caching and reuse of PreparedStatements. Hibernate provides support for Java applications to use c3p0 for connection pooling with additional configuration settings.


2 Answers

Freeing up is totally transparent to the user. See here for further explanation.

Be shure to close() the Connection and hold no further reference (that would avoid proper GC).

like image 151
PeterMmm Avatar answered Sep 30 '22 01:09

PeterMmm


I believe the connection is returned to the pool when you close it.

like image 37
Kevin Avatar answered Sep 30 '22 00:09

Kevin