6

When using Tomcat with MySQL, what is the relationship between poolPreparedStatements setting in Tomcat DataSource configuration (I believe coming from DBCP) and Connector/J cachePrepStmts setting? What's the optimal configuration?

1 Answer 1

5

poolPreparedStatements is a setting for the Tomcat JDBC connection pool and cachePrepStmts is a setting for Connector/J to tell MySQL to cache prepared statements. Two completely different things. cachePrepStmts is a per connection setting, but Connector/J doesn't concern itself with whether it's connecting to a database connection pool or to MySQL directly, yet cachePrepStmts works at it's best with persistent connections (e.g. connection pools). To use cachePrepStmts with a connection pool is the optimal configuration. Using poolPreparedStatements in Tomcat is to open a can of memory management worms (check out the Tomcat docs for this setting and you'll see). Really, it's best to let MySQL cache the prepared statements and let Tomcat pool the connections and not try to have one do the other's job.

2
  • So, you're suggesting that Connector/J will do a better job than DBCP for pooling prepared statements, right? Also, I find this confusing: "Connector/J doesn't concern itself with whether it's connecting to a database connection pool or to MySQL directly". Connector/J is at a lower level than DBCP, so it always connects to MySQL directly, right? Jan 10, 2011 at 21:34
  • 2
    No, MySQL will do a better job of caching prepared statements than DBCP, so set the cachePrepStmts flag in your Connector/J connections and leave the DBCP prep statement pooling alone. Connector/J connects directly to MySQL and DBCP pools a bunch of Connector/J connections. I guess the comment of mine you quoted was garbled and confusing.
    – user187702
    Jan 11, 2011 at 4:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.