Tomcat 中的PreparedStatement 缓存
我正在寻找一种实现PreparedStatement缓存的方法,以便节省为过去已经执行过的查询重新创建PreparedStatement对象的麻烦。
是否有一些内置方法可以使用 Tomcat 实现此目的? 或者我必须自己编程这个缓存?
I am looking for a way to achieve PreparedStatement caching, so as to save recreating the PreparedStatement objects for queries that were already executed in the past.
Is there some built in way to achieve this using Tomcat? Or must I program this cache myself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我相信 tomcat 使用 commons-dbcp 并且 commons-dbcp 支持准备好的语句池。
请查看此处。
poolPreparedStatements false 为此池启用准备好的语句池。
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.
准备好的语句缓存由 JDBC 连接池或 JDBC 驱动程序完成,而不由 Tomcat 完成。
Prepared statement caching is done by either your JDBC connection pool or your JDBC driver, not by Tomcat.
您无需声明您的数据库,但如果它是 SQL Server,则 jTDS 驱动程序会在内部为您执行此操作。 所有这些都被抽象出来,因此您无需编写任何繁琐的缓存代码。
请参阅此处:http://jtds.sourceforge.net/faq.html#preparedStatmentMemoryLeak
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 驱动程序 (JCC) 使用 JDBC 连接属性,例如 maxStatements=10; 它确实缓存了连接的语句。 池不需要缓存它们。
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.
也许我遗漏了您所要求的内容,但如果您在“原始”JDBC 中进行查询,那么基本上您需要做的就是保持连接打开并继续引用PreparedStatement。
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.