org.springframework.jdbc.core

## Class StatementCreatorUtils

- java.lang.Object
- - org.springframework.jdbc.core.StatementCreatorUtils

-     public abstract class StatementCreatorUtils
      extends Object

  Utility methods for PreparedStatementSetter/Creator and CallableStatementCreator implementations, providing sophisticated parameter management (including support for LOB values).

  Used by PreparedStatementCreatorFactory and CallableStatementCreatorFactory, but also available for direct use in custom setter/creator implementations.

  Since:
    1.1
  Author:
    Thomas Risberg, Juergen Hoeller
  See Also:
    `PreparedStatementSetter`, `PreparedStatementCreator`, `CallableStatementCreator`, `PreparedStatementCreatorFactory`, `CallableStatementCreatorFactory`, `SqlParameter`, `SqlTypeValue`, `SqlLobValue`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `IGNORE_GETPARAMETERTYPE_PROPERTY_NAME` System property that instructs Spring to ignore `ParameterMetaData.getParameterType(int)` completely, i.e.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `StatementCreatorUtils()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `cleanupParameters(Collection<?> paramValues)` Clean up all resources held by parameter values which were passed to an execute method.
    `static void` | `cleanupParameters(Object... paramValues)` Clean up all resources held by parameter values which were passed to an execute method.
    `static int` | `javaTypeToSqlParameterType(Class<?> javaType)` Derive a default SQL type from the given Java type.
    `static void` | `setParameterValue(PreparedStatement ps, int paramIndex, int sqlType, Object inValue)` Set the value for a parameter.
    `static void` | `setParameterValue(PreparedStatement ps, int paramIndex, int sqlType, String typeName, Object inValue)` Set the value for a parameter.
    `static void` | `setParameterValue(PreparedStatement ps, int paramIndex, SqlParameter param, Object inValue)` Set the value for a parameter.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### IGNORE_GETPARAMETERTYPE_PROPERTY_NAME

          public static final String IGNORE_GETPARAMETERTYPE_PROPERTY_NAME

      System property that instructs Spring to ignore `ParameterMetaData.getParameterType(int)` completely, i.e. to never even attempt to retrieve `PreparedStatement.getParameterMetaData()` for `setNull(java.sql.PreparedStatement, int, int, java.lang.String)` calls.

      The default is "false", trying `getParameterType` calls first and falling back to `PreparedStatement.setNull(int, int)` / `PreparedStatement.setObject(int, java.lang.Object, int)` calls based on well-known behavior of common databases. Spring records JDBC drivers with non-working `getParameterType` implementations and won't attempt to call that method for that driver again, always falling back.

      Consider switching this flag to "true" if you experience misbehavior at runtime, e.g. with a connection pool setting back the `PreparedStatement` instance in case of an exception thrown from `getParameterType` (as reported on JBoss AS 7).

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### StatementCreatorUtils

          public StatementCreatorUtils()

  - ### Method Detail

    - #### javaTypeToSqlParameterType

          public static int javaTypeToSqlParameterType(Class<?> javaType)

      Derive a default SQL type from the given Java type.
      Parameters:
        `javaType` - the Java type to translate
      Returns:
        the corresponding SQL type, or `null` if none found

    - #### setParameterValue

          public static void setParameterValue(PreparedStatement ps,
                                               int paramIndex,
                                               SqlParameter param,
                                               Object inValue)
                                        throws SQLException

      Set the value for a parameter. The method used is based on the SQL type of the parameter and we can handle complex types like arrays and LOBs.
      Parameters:
        `ps` - the prepared statement or callable statement
        `paramIndex` - index of the parameter we are setting
        `param` - the parameter as it is declared including type
        `inValue` - the value to set
      Throws:
        `SQLException` - if thrown by PreparedStatement methods

    - #### setParameterValue

          public static void setParameterValue(PreparedStatement ps,
                                               int paramIndex,
                                               int sqlType,
                                               Object inValue)
                                        throws SQLException

      Set the value for a parameter. The method used is based on the SQL type of the parameter and we can handle complex types like arrays and LOBs.
      Parameters:
        `ps` - the prepared statement or callable statement
        `paramIndex` - index of the parameter we are setting
        `sqlType` - the SQL type of the parameter
        `inValue` - the value to set (plain value or a SqlTypeValue)
      Throws:
        `SQLException` - if thrown by PreparedStatement methods
      See Also:
        `SqlTypeValue`

    - #### setParameterValue

          public static void setParameterValue(PreparedStatement ps,
                                               int paramIndex,
                                               int sqlType,
                                               String typeName,
                                               Object inValue)
                                        throws SQLException

      Set the value for a parameter. The method used is based on the SQL type of the parameter and we can handle complex types like arrays and LOBs.
      Parameters:
        `ps` - the prepared statement or callable statement
        `paramIndex` - index of the parameter we are setting
        `sqlType` - the SQL type of the parameter
        `typeName` - the type name of the parameter (optional, only used for SQL NULL and SqlTypeValue)
        `inValue` - the value to set (plain value or a SqlTypeValue)
      Throws:
        `SQLException` - if thrown by PreparedStatement methods
      See Also:
        `SqlTypeValue`

    - #### cleanupParameters

          public static void cleanupParameters(Object... paramValues)

      Clean up all resources held by parameter values which were passed to an execute method. This is for example important for closing LOB values.
      Parameters:
        `paramValues` - parameter values supplied. May be `null`.
      See Also:
        `DisposableSqlTypeValue.cleanup()`, `SqlLobValue.cleanup()`

    - #### cleanupParameters

          public static void cleanupParameters(Collection<?> paramValues)

      Clean up all resources held by parameter values which were passed to an execute method. This is for example important for closing LOB values.
      Parameters:
        `paramValues` - parameter values supplied. May be `null`.
      See Also:
        `DisposableSqlTypeValue.cleanup()`, `SqlLobValue.cleanup()`