PreparedStatement缓存-是什么意思(它是如何工作的) [英] PreparedStatement caching - what does it mean (how does it work)

查看:466
本文介绍了PreparedStatement缓存-是什么意思(它是如何工作的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我将c3p0与某些已定义的"maxStatements"一起用于prepareStatement缓存. 这种缓存实际上有什么作用?它缓存什么样的数据.在什么级别(数据库,应用程序,..)? 从示例中理解它会很高兴.例如我有一个查询

I'm using for example c3p0 with some defined "maxStatements" for preparedStatement caching. What does this caching really do? What kind of data it caches. On what level (db, application,..)? It will be nice to understand it from example. For example i have a query

从某表中选择* * somecolumn =?

select * from sometable where somecolumn=?

现在,我以未缓存的准备好的语句发送它. 现在,我正在发送它,并将其缓存. 有什么区别.在第一种情况和第二种情况中发生了什么.在第一种情况下和第二种情况下,发送到数据库服务器的内容是什么?

Now i send it in prepared statement that is not cached. And now i'm sending it and it is cached. What the difference. What happened in the first case and in the second. What is sent to DB server in the first case and in the second?

谢谢.

推荐答案

如果不进行缓存,则每次从Connection请求一个新的PreparedStatement.使用缓存,如果提供相同的SQL字符串,则经常会得到类型与PreparedStatement完全相同的Java对象.如果您向PreparedStatement提供相同的SQL,甚至使用不同的参数,则数据库通常可以重用信息,例如执行计划,但前提是您继续使用相同的PreparedStatement.通过缓存,不需要您的应用程序本身就保留了PreparedStatement引用,可以简化此操作.

Without caching, you will get a new PreparedStatement each time you request one from the Connection. With caching, you will frequently get the exact same Java object of type PreparedStatement if you provide the same SQL string. If you provide the same SQL to a PreparedStatement, even with different parameters, often the database can reuse information like the execution plan, but only if you continue to use the same PreparedStatement. Caching makes that easier by not requiring your app to hold on to that PreparedStatement reference itself.

这篇关于PreparedStatement缓存-是什么意思(它是如何工作的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆