views:

133

answers:

2

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?

A: 

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

Kevin
I was wondering if that was the case. So is it not really closed in the data source? I'm guessing c3p0 just wraps the data source's Connection implementation, intercepts the close() call and reuses the Connection. Is that correct?
jtbradle
+1  A: 

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).

PeterMmm
Thanks, that works!
jtbradle