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?
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.
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..
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.
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).
I believe the connection is returned to the pool when you close it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With