Interface PreparedStatementBinder

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

Contract for binding parameters to SQL prepared statements.

A production-ready concrete implementation is available via the following static methods:

How to acquire an instance:
 // With out-of-the-box defaults
PreparedStatementBinder default = PreparedStatementBinder.withDefaultConfiguration();

// Customized
PreparedStatementBinder custom = PreparedStatementBinder.withCustomParameterBinders(List.of(...));
Or, implement your own:
 PreparedStatementBinder myImpl = new PreparedStatementBinder() {
  @Override
  <T> void bindParameter(
    @NonNull StatementContext<T> statementContext,
    @NonNull PreparedStatement preparedStatement,
    @NonNull Integer parameterIndex,
    @NonNull Object parameter
  ) throws SQLException {
    // Bind the parameter at the specified index to the PreparedStatement
  }
};
Since:
1.0.0
Author:
Mark Allen
  • Method Details

    • bindParameter

      <T> void bindParameter(@NonNull StatementContext<T> statementContext, @NonNull PreparedStatement preparedStatement, @NonNull Integer parameterIndex, @NonNull Object parameter) throws SQLException
      Binds a single parameter to a SQL prepared statement.

      This function is only invoked when parameter is non-null.

      Parameters:
      statementContext - current SQL context
      preparedStatement - the prepared statement to bind to
      parameterIndex - the index of the parameter we are binding
      parameter - the parameter we are binding to the PreparedStatement, if any
      Throws:
      SQLException - if an error occurs during binding
    • withDefaultConfiguration

      Acquires a concrete implementation of this interface with out-of-the-box defaults.

      The returned instance is thread-safe.

      Returns:
      a concrete implementation of this interface with out-of-the-box defaults
    • withCustomParameterBinders

      static @NonNull PreparedStatementBinder withCustomParameterBinders(@NonNull List<CustomParameterBinder> customParameterBinders)
      Acquires a concrete implementation of this interface, specifying "surgical" per-type custom parameter binders.

      The returned instance is thread-safe.

      Parameters:
      customParameterBinders - the "surgical" per-type custom parameter binders
      Returns:
      a concrete implementation of this interface