类 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.
- 从以下版本开始:
- 1.1
- 作者:
- Thomas Risberg, Juergen Hoeller
- 另请参阅:
PreparedStatementSetter
,PreparedStatementCreator
,CallableStatementCreator
,PreparedStatementCreatorFactory
,CallableStatementCreatorFactory
,SqlParameter
,SqlTypeValue
,SqlLobValue
字段概要
字段 修饰符和类型 字段 说明 static String
IGNORE_GETPARAMETERTYPE_PROPERTY_NAME
System property that instructs Spring to ignoreParameterMetaData.getParameterType(int)
completely, i.e. to never even attempt to retrievePreparedStatement.getParameterMetaData()
forsetNull(java.sql.PreparedStatement, int, int, java.lang.String)
calls.
构造器概要
构造器 构造器 说明 StatementCreatorUtils()
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static void
cleanupParameters(Object... paramValues)
Clean up all resources held by parameter values which were passed to an execute method.static void
cleanupParameters(Collection<?> 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.
字段详细资料
IGNORE_GETPARAMETERTYPE_PROPERTY_NAME
public static final String IGNORE_GETPARAMETERTYPE_PROPERTY_NAME
System property that instructs Spring to ignoreParameterMetaData.getParameterType(int)
completely, i.e. to never even attempt to retrievePreparedStatement.getParameterMetaData()
forsetNull(java.sql.PreparedStatement, int, int, java.lang.String)
calls.The effective default is "false", trying
getParameterType
calls first and falling back toPreparedStatement.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-workinggetParameterType
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 connection pool issues in case of an exception thrown from
getParameterType
(as reported on JBoss AS 7) or in case of performance problems (as reported on PostgreSQL).Note that this flag is "true" by default on Oracle 12c since there can be leaks created by
getParameterType
calls in such a scenario. You need to explicitly set the flag to "false" in order to enforce the use ofgetParameterType
against Oracle drivers.- 另请参阅:
- 常量字段值
构造器详细资料
StatementCreatorUtils
public StatementCreatorUtils()
方法详细资料
javaTypeToSqlParameterType
public static int javaTypeToSqlParameterType(Class<?> javaType)
Derive a default SQL type from the given Java type.- 参数:
javaType
- the Java type to translate- 返回:
- the corresponding SQL type, or
SqlTypeValue.TYPE_UNKNOWN
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.- 参数:
ps
- the prepared statement or callable statementparamIndex
- index of the parameter we are settingparam
- the parameter as it is declared including typeinValue
- the value to set- 抛出:
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.- 参数:
ps
- the prepared statement or callable statementparamIndex
- index of the parameter we are settingsqlType
- the SQL type of the parameterinValue
- the value to set (plain value or a SqlTypeValue)- 抛出:
SQLException
- if thrown by PreparedStatement methods- 另请参阅:
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.- 参数:
ps
- the prepared statement or callable statementparamIndex
- index of the parameter we are settingsqlType
- the SQL type of the parametertypeName
- the type name of the parameter (optional, only used for SQL NULL and SqlTypeValue)inValue
- the value to set (plain value or a SqlTypeValue)- 抛出:
SQLException
- if thrown by PreparedStatement methods- 另请参阅:
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.- 参数:
paramValues
- parameter values supplied. May benull
.- 另请参阅:
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.- 参数:
paramValues
- parameter values supplied. May benull
.- 另请参阅:
DisposableSqlTypeValue.cleanup()
,SqlLobValue.cleanup()