public abstract class AbstractSqlTypeValue extends Object implements SqlTypeValue
PreparedStatement.setObject
method. The createTypeValue
callback method has access to the underlying Connection, if that should
be needed to create any database-specific objects.
A usage example from a StoredProcedure (compare this to the plain SqlTypeValue version in the superclass javadoc):
proc.declareParameter(new SqlParameter("myarray", Types.ARRAY, "NUMBERS")); ... Map<String, Object> in = new HashMap<String, Object>(); in.put("myarray", new AbstractSqlTypeValue() { public Object createTypeValue(Connection con, int sqlType, String typeName) throws SQLException { oracle.sql.ArrayDescriptor desc = new oracle.sql.ArrayDescriptor(typeName, con); return new oracle.sql.ARRAY(desc, con, seats); } }); Map out = execute(in);
PreparedStatement.setObject(int, Object, int)
,
StoredProcedure
TYPE_UNKNOWN
Constructor and Description |
---|
AbstractSqlTypeValue() |
Modifier and Type | Method and Description |
---|---|
protected abstract Object |
createTypeValue(Connection con,
int sqlType,
String typeName)
Create the type value to be passed into
PreparedStatement.setObject . |
void |
setTypeValue(PreparedStatement ps,
int paramIndex,
int sqlType,
String typeName)
Set the type value on the given PreparedStatement.
|
public final void setTypeValue(PreparedStatement ps, int paramIndex, int sqlType, @Nullable String typeName) throws SQLException
SqlTypeValue
setTypeValue
in interface SqlTypeValue
ps
- the PreparedStatement to work onparamIndex
- the index of the parameter for which we need to set the valuesqlType
- the SQL type of the parameter we are settingtypeName
- the type name of the parameter (optional)SQLException
- if an SQLException is encountered while setting parameter valuesTypes
,
PreparedStatement.setObject(int, java.lang.Object, int)
protected abstract Object createTypeValue(Connection con, int sqlType, @Nullable String typeName) throws SQLException
PreparedStatement.setObject
.con
- the JDBC Connection, if needed to create any database-specific objectssqlType
- the SQL type of the parameter we are settingtypeName
- the type name of the parameterSQLException
- if an SQLException is encountered setting
parameter values (that is, there's no need to catch SQLException)PreparedStatement.setObject(int, Object, int)