public abstract class StatementCreatorUtils extends Object
Used by PreparedStatementCreatorFactory and CallableStatementCreatorFactory, but also available for direct use in custom setter/creator implementations.
PreparedStatementSetter
,
PreparedStatementCreator
,
CallableStatementCreator
,
PreparedStatementCreatorFactory
,
CallableStatementCreatorFactory
,
SqlParameter
,
SqlTypeValue
,
SqlLobValue
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 and Description |
---|
StatementCreatorUtils() |
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.
|
public static final String IGNORE_GETPARAMETERTYPE_PROPERTY_NAME
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).
public static int javaTypeToSqlParameterType(Class<?> javaType)
javaType
- the Java type to translatenull
if none foundpublic static void setParameterValue(PreparedStatement ps, int paramIndex, SqlParameter param, Object inValue) throws SQLException
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 setSQLException
- if thrown by PreparedStatement methodspublic static void setParameterValue(PreparedStatement ps, int paramIndex, int sqlType, Object inValue) throws SQLException
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 methodsSqlTypeValue
public static void setParameterValue(PreparedStatement ps, int paramIndex, int sqlType, String typeName, Object inValue) throws SQLException
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 methodsSqlTypeValue
public static void cleanupParameters(Object... paramValues)
paramValues
- parameter values supplied. May be null
.DisposableSqlTypeValue.cleanup()
,
SqlLobValue.cleanup()
public static void cleanupParameters(Collection<?> paramValues)
paramValues
- parameter values supplied. May be null
.DisposableSqlTypeValue.cleanup()
,
SqlLobValue.cleanup()