Interface PreparedStatement


public interface PreparedStatement

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 Details

    • 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

      PreparedStatement bindAt(int index, Object value)

      Binds the specified value at the specified index in the current arguments binding

      Parameters:
      index - the index of the argument
      value - the argument value
      Returns:
      this statement
    • bindNullAt

      PreparedStatement bindNullAt(int index, Class<?> type)

      Binds a null value of the specified type at the specified index in the current arguments binding.

      Parameters:
      index - the index of the argument
      type - the type of argument
      Returns:
      this statement
    • bind

      PreparedStatement bind(Object... values)

      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

      PreparedStatement bind(List<Object[]> values)

      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

      PreparedStatement bind(Stream<Object[]> values)

      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

      PreparedStatement fetchSize(int rows)

      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

      Resets the statement by removing all bindings.

      Returns:
      this statement
    • execute

      Publisher<SqlResult> 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

      <T> Publisher<T> execute(Function<Row,T> rowMapper)

      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