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?
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.
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.
In short:
Statement
: batch can contain a lot of different statementsPreparedStatement
: single statement, multiple sets of parameter valuesIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With