PreparedStatement批处理与Statement批处理之间的区别 [英] Difference between PreparedStatement batch and Statement batch
问题描述
此刻我正在学习JDBC,我已经知道PreparedStatement和Statement之间的区别.是PreparedStatement是预编译的,并允许您设置参数,但是在工作面试中有人问我有关PreparedStatement批处理与Statement批处理之间的区别的问题?
I'm learning JDBC at the moment and I already know the difference between PreparedStatement and Statement. It is that PreparedStatement is precompiled and allows you to set parameters, but I was asked a question on a job interview about difference between PreparedStatement batch and Statement batch?
推荐答案
Statement
和PreparedStatement
的批处理执行之间的区别在于,Statement
批处理可以包含不同的语句(只要它们是语句)不会产生结果集),例如,单个批处理可以包含对各种表的各种插入,删除,更新,并且-并非在所有JDBC驱动程序实现AFAIK中-甚至是DDL语句.
The difference between batch execution of a Statement
and PreparedStatement
, is that a Statement
batch can contain different statements (as long as they are statements that do not produce a result set), for example a single batch can contain all kinds of inserts into various tables, deletes, updates, and - not in all JDBC driver implementations AFAIK - even DDL statements.
另一方面,PreparedStatement
批处理执行涉及单个语句,并且该批处理包含要为该语句执行的多组参数值.也就是说,每个批处理条目都定义了用于准备好的语句的参数的值.
On the other hand, a PreparedStatement
batch execution concerns a single statement, and the batch contains the multiple sets of parameter values to execute for that statement. That is, each batch entry defines the values to use for the parameters of the prepared statement.
简而言之:
-
Statement
:批处理可以包含许多不同的语句 -
PreparedStatement
:单个语句,多组参数值
Statement
: batch can contain a lot of different statementsPreparedStatement
: single statement, multiple sets of parameter values
这篇关于PreparedStatement批处理与Statement批处理之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!