PreparedStatement caching in Tomcat

杀马特。学长 韩版系。学妹 提交于 2019-12-05 08:51:53

I believe tomcat uses commons-dbcp and commons-dbcp supports prepared statement pooling.

check it out here.

poolPreparedStatements false Enable prepared statement pooling for this pool.

Prepared statement caching is done by either your JDBC connection pool or your JDBC driver, not by Tomcat.

You don't state your database, but if it's SQL Server then the jTDS driver does this internally for you. It's all abstracted away so you don't need to write any hairy caching code.

See here: http://jtds.sourceforge.net/faq.html#preparedStatmentMemoryLeak

DB2 JDBC Driver (JCC) uses a JDBC connection property like maxStatements=10; and it does cache the statements for the connection. The pool need not cache them.

Perhaps I'm missing something in what you're asking, but if you're making your queries in "raws" JDBC, then essentially all you need to do is keep the connection open and keep on to a reference to the PreparedStatement.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!