准备的语句和JDBC驱动程序 [英] Prepared Statements and JDBC Drivers

查看:78
本文介绍了准备的语句和JDBC驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Java中的预处理语句有以下疑问.

I have the below questions on Prepared Statements in Java.

  1. 当SQL查询中没有任何Where子句时,使用Prepared Statements是否有益?假设一个简单的查询从表名中选择*;

  1. Is it beneficial to use Prepared Statements when the SQL Query does not have any Where clause ? Assume a simple query Select * from tablename;

据说,Prepared语句仅编译一次,而第二次仅替换值.因此,它可以更快,因为可以跳过查询验证和编译步骤.编译后的表格存储在哪里?这种编译形式的寿命是多少?

It is said that the Prepared Statement is compiled once and only the values are substituted the second time. Hence it is faster as the Query validation and compilation step can be skipped. Where is the compiled form stored ? What is the life time of this compiled form ?

推荐答案

  1. 当有要传递的参数并且要重复执行查询时,PreparedStatement很有用.如果有一个简单的查询要触发一次,则一条Statement会证明更快.

  1. A PreparedStatement is beneficial when there are parameters to be passed and when the query is to be executed repeatedly. If there is a simple query to be fired once, a Statement will prove faster.

缓存在数据库服务器上进行.数据库服务器具有帮助缓存已编译查询的API.因此,对于重复执行查询,相同的编译查询将再次运行并提高性能.

The caching takes place on DB server. The DB server has APIs that help caching compiled queries. Hence for repeated execution of queries, the same compiled query will run again and boost performance.

这篇关于准备的语句和JDBC驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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