What Exactly is Cached with C3P0 Statement Pooling

95 Views Asked by At

This is probably a very easy question, but I cannot seem to find a definitive answer one way or another in the documentation or in previously posted similar questions. When enabling statement pooling, which is caching instances of PreparedStatements in C3P0 (setting maxStatements and / or maxStatementsPerConnection to a value greater than 0) are the statements cached with or without the parameters? My application uses a lot of the same queries but not with the same parameters frequently, and knowing this would (I assume) determine whether or not this feature is worthwhile.

Versions:

Hibernate 5.0.3.Final

c3p0 0.9.2.1

1

There are 1 best solutions below

0
Steve Waldman On BEST ANSWER

PreparedStatements are cached, not their parameterizations. You must reparameterize PreparedStatements prior to each use.

In general c3p0 implements transparent pooling: Acquiring a cached Connection or PreparedStatement is made to the maximum extent possible equivalent to acquiring a new Connection or PreparedStatement, just much faster. From an application developer's perspective, there's no difference between a cached PreparedStatement and one newly prepared.