spring-framework / org.springframework.jdbc.core / StatementCreatorUtils

StatementCreatorUtils

abstract class StatementCreatorUtils

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.

Author
Thomas Risberg

Author
Juergen Hoeller

Since
1.1

See Also
PreparedStatementSetterPreparedStatementCreatorCallableStatementCreatorPreparedStatementCreatorFactoryCallableStatementCreatorFactorySqlParameterSqlTypeValueorg.springframework.jdbc.core.support.SqlLobValue

Constructors

<init>

StatementCreatorUtils()

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.

Properties

IGNORE_GETPARAMETERTYPE_PROPERTY_NAME

static val IGNORE_GETPARAMETERTYPE_PROPERTY_NAME: String

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

The default is "false", trying getParameterType calls first and falling back to PreparedStatement#setNull / PreparedStatement#setObject 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).

Functions

cleanupParameters

open static fun cleanupParameters(vararg paramValues: Any): Unit
open static fun cleanupParameters(paramValues: MutableCollection<*>): Unit

Clean up all resources held by parameter values which were passed to an execute method. This is for example important for closing LOB values.

javaTypeToSqlParameterType

open static fun javaTypeToSqlParameterType(javaType: Class<*>): Int

Derive a default SQL type from the given Java type.

setParameterValue

open static fun setParameterValue(ps: PreparedStatement, paramIndex: Int, param: SqlParameter, inValue: Any): Unit
open static fun setParameterValue(ps: PreparedStatement, paramIndex: Int, sqlType: Int, inValue: Any): Unit
open static fun setParameterValue(ps: PreparedStatement, paramIndex: Int, sqlType: Int, typeName: String, inValue: Any): Unit

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.