Java – Tomcat connection pooling with prepared statement cache

connection-poolingjavajdbctomcat

Having upgraded from DBCP connection pooling to Tomcat's own implementation (based on the excellent comparison here); I'm a little confused as to why they've dropped these 2 properties, while keeping everything else:

poolPreparedStatements="true"
maxOpenPreparedStatements="10000"

Does this mean that prepared statement pooling is not supported in this implementation? And does each connection maintain its own pool of prepared statements by default?

I've spent a considerable time researching this and have found no clear answer!

Thanks for your time.

Best Answer

Tomcat's (fairly) new jdbc-pool does have a statement cache, too. You can enable and configure it using a JDBC interceptor, which is set as a JDBC property during pool creation.
Please have a look at the documentation for more information and which configuration possibilities exist.

It's basically done this way:

      PoolProperties p = new PoolProperties();
      p.setUrl("jdbc:your-jdbc-url");
      p.setDriverClassName("your.jdbc.driver.class");
      p.setUsername("user");
      p.setPassword("password");
      p.setJdbcInterceptors(
        "org.apache.tomcat.jdbc.pool.interceptor.StatementCache");
      DataSource datasource = new DataSource();
      datasource.setPoolProperties(p);
Related Topic