Interface PreparedStatementSupport


public interface PreparedStatementSupport
Interface providing utility methods for setting parameters in a PreparedStatement with nullable values. This interface is intended to simplify handling of null values when setting parameters in SQL statements.
  • Method Details

    • setIntOrNull

      default void setIntOrNull(PreparedStatement ps, int parameterIndex, Integer value) throws SQLException
      Sets the specified parameter to an integer value or to NULL in a PreparedStatement. If the provided value is non-null, it sets the parameter to the integer value; otherwise, it sets the parameter to NULL with the SQL type Types.INTEGER.
      Parameters:
      ps - the PreparedStatement where the parameter will be set
      parameterIndex - the index of the parameter to set, starting from 1
      value - the Integer value to set, or null to set the parameter to NULL
      Throws:
      SQLException - if a database access error occurs or the parameter index is invalid
    • setIntOrDefault

      default void setIntOrDefault(PreparedStatement ps, int parameterIndex, Integer value, Integer defaultValue) throws SQLException
      Sets the specified parameter to an integer value or a default value in a PreparedStatement. If the provided value is non-null, it sets the parameter to the integer value; otherwise, it sets the parameter to the provided default value.
      Parameters:
      ps - the PreparedStatement where the parameter will be set
      parameterIndex - the index of the parameter to set, starting from 1
      value - the Integer value to set, or null to use the default value
      defaultValue - the Integer value to use if the provided value is null
      Throws:
      SQLException - if a database access error occurs or the parameter index is invalid
    • setLongOrNull

      default void setLongOrNull(PreparedStatement ps, int parameterIndex, Long value) throws SQLException
      Sets the specified parameter to a long value or to NULL in a PreparedStatement. If the provided value is non-null, it sets the parameter to the long value; otherwise, it sets the parameter to NULL with the SQL type Types.BIGINT.
      Parameters:
      ps - the PreparedStatement where the parameter will be set
      parameterIndex - the index of the parameter to set, starting from 1
      value - the Long value to set, or null to set the parameter to NULL
      Throws:
      SQLException - if a database access error occurs or the parameter index is invalid
    • setLongOrDefault

      default void setLongOrDefault(PreparedStatement ps, int parameterIndex, Long value, Long defaultValue) throws SQLException
      Sets the specified parameter to a long value or a default value in a PreparedStatement. If the provided value is non-null, it sets the parameter to the long value; otherwise, it sets the parameter to the provided default value.
      Parameters:
      ps - the PreparedStatement where the parameter will be set
      parameterIndex - the index of the parameter to set, starting from 1
      value - the Long value to set, or null to use the default value
      defaultValue - the Long value to use if the provided value is null
      Throws:
      SQLException - if a database access error occurs or the parameter index is invalid
    • setDoubleOrNull

      default void setDoubleOrNull(PreparedStatement ps, int parameterIndex, Double value) throws SQLException
      Sets the specified parameter to a double value or to NULL in a PreparedStatement. If the provided value is non-null, it sets the parameter to the double value; otherwise, it sets the parameter to NULL with the SQL type Types.DOUBLE.
      Parameters:
      ps - the PreparedStatement where the parameter will be set
      parameterIndex - the index of the parameter to set, starting from 1
      value - the Double value to set, or null to set the parameter to NULL
      Throws:
      SQLException - if a database access error occurs or the parameter index is invalid
    • setDoubleOrDefault

      default void setDoubleOrDefault(PreparedStatement ps, int parameterIndex, Double value, Double defaultValue) throws SQLException
      Sets the specified parameter to a double value or a default value in a PreparedStatement. If the provided value is non-null, it sets the parameter to the double value; otherwise, it sets the parameter to the provided default value.
      Parameters:
      ps - the PreparedStatement where the parameter will be set
      parameterIndex - the index of the parameter to set, starting from 1
      value - the Double value to set, or null to use the default value
      defaultValue - the Double value to use if the provided value is null
      Throws:
      SQLException - if a database access error occurs or the parameter index is invalid
    • setBooleanOrNull

      default void setBooleanOrNull(PreparedStatement ps, int parameterIndex, Boolean value) throws SQLException
      Sets the specified parameter to a boolean value or to NULL in a PreparedStatement. If the provided value is non-null, it sets the parameter to the boolean value; otherwise, it sets the parameter to NULL with the SQL type Types.BOOLEAN.
      Parameters:
      ps - the PreparedStatement where the parameter will be set
      parameterIndex - the index of the parameter to set, starting from 1
      value - the Boolean value to set, or null to set the parameter to NULL
      Throws:
      SQLException - if a database access error occurs or the parameter index is invalid
    • setBooleanOrDefault

      default void setBooleanOrDefault(PreparedStatement ps, int parameterIndex, Boolean value, Boolean defaultValue) throws SQLException
      Sets the specified parameter to a boolean value or a default value in a PreparedStatement. If the provided value is non-null, it sets the parameter to the boolean value; otherwise, it sets the parameter to the provided default value.
      Parameters:
      ps - the PreparedStatement where the parameter will be set
      parameterIndex - the index of the parameter to set, starting from 1
      value - the Boolean value to set, or null to use the default value
      defaultValue - the Boolean value to use if the provided value is null
      Throws:
      SQLException - if a database access error occurs or the parameter index is invalid
    • setObjectOrNull

      default void setObjectOrNull(PreparedStatement ps, int parameterIndex, Object value, int type) throws SQLException
      Sets the specified parameter in a PreparedStatement to the given object value or to NULL. If the provided value is non-null, it sets the parameter to the object value with the specified SQL type. Otherwise, it sets the parameter to NULL with the given SQL type.
      Parameters:
      ps - the PreparedStatement where the parameter will be set
      parameterIndex - the index of the parameter to set, starting from 1
      value - the object value to set, or null to set the parameter to NULL
      type - the SQL type to use when setting the parameter
      Throws:
      SQLException - if a database access error occurs or the parameter index is invalid
    • setZonedDateTimeOrNull

      default void setZonedDateTimeOrNull(PreparedStatement ps, int parameterIndex, ZonedDateTime value) throws SQLException
      Sets the specified parameter in a PreparedStatement to the given ZonedDateTime value or to NULL. If the provided ZonedDateTime value is non-null, it is converted to an OffsetDateTime and the parameter is set using the SQL type Types.TIMESTAMP_WITH_TIMEZONE. Otherwise, the parameter is set to NULL with the SQL type Types.TIMESTAMP_WITH_TIMEZONE.
      Parameters:
      ps - the PreparedStatement where the parameter will be set
      parameterIndex - the index of the parameter to set, starting from 1
      value - the ZonedDateTime value to set, or null to set the parameter to NULL
      Throws:
      SQLException - if a database access error occurs or the parameter index is invalid
    • setZonedDateTimeOrDefault

      default void setZonedDateTimeOrDefault(PreparedStatement ps, int parameterIndex, ZonedDateTime value, ZonedDateTime defaultValue) throws SQLException
      Sets the specified parameter to the given ZonedDateTime value or a default value in a PreparedStatement. If the provided ZonedDateTime value is non-null, it is converted to an OffsetDateTime and the parameter is set using the SQL type Types.TIMESTAMP_WITH_TIMEZONE. Otherwise, the parameter is set to the provided defaultValue, which is also converted to an OffsetDateTime and set using the same SQL type.
      Parameters:
      ps - the PreparedStatement where the parameter will be set
      parameterIndex - the index of the parameter to set, starting from 1
      value - the ZonedDateTime value to set, or null to use the default value
      defaultValue - the ZonedDateTime value to use if the provided value is null
      Throws:
      SQLException - if a database access error occurs or the parameter index is invalid
    • setJsonbOrNull

      default void setJsonbOrNull(PreparedStatement ps, int parameterIndex, Object value, Class<?> clazz, com.fasterxml.jackson.databind.ObjectMapper mapper) throws SQLException
      Sets the given value as a JSONB string in the specified parameter index of the PreparedStatement. If the value is null, sets the parameter to SQL null with the type Types.OTHER.
      Parameters:
      ps - the PreparedStatement to set the parameter on
      parameterIndex - the index of the parameter to set
      value - the object value to serialize and set as a JSONB string, or null to set SQL null
      clazz - the Class type of the value being serialized (not directly used in this method)
      mapper - the ObjectMapper instance used to serialize the object to JSONB
      Throws:
      SQLException - if a database access error occurs or object serialization to JSON fails