小编TBa*_*Bag的帖子

如果我关闭PreparedStatement,数据库中的缓存是否会丢失?

PreparedStatment ps = null;
public void executeQueries(){
    try{
        ps = conn.prepareStatement(Query1);
        // Execute Query1 here and do the processing.           

        ps = conn.prepareStatement(Query2);
        // Execute Query2 here and do the processing.

        //... more queries
    }catch(){}
    finally{
        ps.close(); // At this point would the caching of queries in DB be lost?
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的应用程序中,我executeQueries()经常调用该方法.

我的问题是,如果我关闭PreparedStatement方法中的finally块(我经常使用),数据库系统会删除缓存吗?如果是,我可以PreparedStatement为整个应用程序创建一个全局,因为在我的应用程序中有大量的JAVA CLASSES查询数据库.

谢谢!

更新:问题已标记为重复,但链接的线程根本不回答我的问题.AFAIK,数据库系统将执行的查询存储在高速缓冲存储器中.它还存储了他们的执行计划.这是PreparedStatement比穿着更好的地方Statement.但是,我不确定PreparedStatement关闭后是否删除与查询相关的信息.

java mysql jdbc oracle11g

5
推荐指数
1
解决办法
103
查看次数

标签 统计

java ×1

jdbc ×1

mysql ×1

oracle11g ×1