The prepared statement is pre-compiled, it should be preferred over regular statements as it is more efficient when executed multiple times and it protects against SQL injection attacks.
A prepared statement can execute operations in a batch as well by providing multiple bindings before execution.
- Since:
- 1.2
- Author:
- Jeremy Kuhn
-
Method Summary
Modifier and TypeMethodDescriptionand()
Appends current arguments binding to the batch and creates another binding.Sets the specified list of values as the current arguments binding.Adds multiple arguments bindings at once.Adds multiple arguments bindings at once.Binds the specified value at the specified index in the current arguments bindingbindNullAt
(int index, Class<?> type) Binds a null value of the specified type at the specified index in the current arguments binding.execute()
Executes the statement and returns a sequence of results corresponding to the bindings.<T> Publisher
<T> Executes the statement, applies a row mapping function to the resulting rows and returns the results.fetchSize
(int rows) Specifies the fetch size when rows are retrieved in a stream.reset()
Resets the statement by removing all bindings.
-
Method Details
-
and
PreparedStatement and()Appends current arguments binding to the batch and creates another binding.
This method is used to chain arguments bindings in a fluent way.
- Returns:
- this statement
-
bindAt
Binds the specified value at the specified index in the current arguments binding
- Parameters:
index
- the index of the argumentvalue
- the argument value- Returns:
- this statement
-
bindNullAt
Binds a null value of the specified type at the specified index in the current arguments binding.
- Parameters:
index
- the index of the argumenttype
- the type of argument- Returns:
- this statement
-
bind
Sets the specified list of values as the current arguments binding.
Note that this will replace current arguments binding.
- Parameters:
values
- the argument values to set- Returns:
- this statement
-
bind
Adds multiple arguments bindings at once.
This is is a shortcut for
.and().bind(...).and().bind(...)...
that appends the specified list of bindings to the current batch.- Parameters:
values
- a list of argument bindings- Returns:
- this statement
-
bind
Adds multiple arguments bindings at once.
This is is a shortcut for
.and().bind(...).and().bind(...)...
that appends the specified list of bindings to the current batch.- Parameters:
values
- a stream of argument bindings- Returns:
- this statement
-
fetchSize
Specifies the fetch size when rows are retrieved in a stream.
The fetch size is set to 0 by default and streaming is disabled.
If streaming is not available, this is a noop method.
- Parameters:
rows
- the number of rows to fetch or 0 to disable streaming- Returns:
- this statement
-
reset
PreparedStatement reset()Resets the statement by removing all bindings.
- Returns:
- this statement
-
execute
Executes the statement and returns a sequence of results corresponding to the bindings.
When multiple parameters bindings are specified, the statement is executed in a batch and one result is emitted per parameters binding.
- Returns:
- a publisher of results
-
execute
Executes the statement, applies a row mapping function to the resulting rows and returns the results.
- Type Parameters:
T
- the type of results- Parameters:
rowMapper
- a row mapping function- Returns:
- a publisher of results
-