Top Description Fields Constructors Methods
org.springframework.jdbc.core.simple

public Class SimpleJdbcCall

extends AbstractJdbcCall
implements SimpleJdbcCallOperations
Class Inheritance
All Implemented Interfaces
org.springframework.jdbc.core.simple.SimpleJdbcCallOperations
Imports
java.util.Arrays, .LinkedHashSet, .Map, javax.sql.DataSource, org.springframework.jdbc.core.JdbcTemplate, .RowMapper, .SqlParameter, org.springframework.jdbc.core.namedparam.SqlParameterSource

A SimpleJdbcCall is a multithreaded, reusable object representing a call to a stored procedure or a stored function. It provides meta-data processing to simplify the code needed to access basic stored procedures/functions. All you need to provide is the name of the procedure/function and a Map containing the parameters when you execute the call. The names of the supplied parameters will be matched up with in and out parameters declared when the stored procedure was created.

The meta-data processing is based on the DatabaseMetaData provided by the JDBC driver. Since we rely on the JDBC driver, this "auto-detection" can only be used for databases that are known to provide accurate meta-data. These currently include Derby, MySQL, Microsoft SQL Server, Oracle, DB2, Sybase and PostgreSQL. For any other databases you are required to declare all parameters explicitly. You can of course declare all parameters explicitly even if the database provides the necessary meta-data. In that case your declared parameters will take precedence. You can also turn off any meta-data processing if you want to use parameter names that do not match what is declared during the stored procedure compilation.

The actual call is being handled using Spring's JdbcTemplate.

Many of the configuration methods return the current instance of the SimpleJdbcCall in order to provide the ability to chain multiple ones together in a "fluent" interface style.

Authors
Thomas Risberg, Stephane Nicoll
Since
2.5
See Also
java.sql.DatabaseMetaData, org.springframework.jdbc.core.JdbcTemplate

Field Summary

Inherited from org.springframework.jdbc.core.simple.AbstractJdbcCall:
logger

Constructor Summary

AccessConstructor and Description
public
SimpleJdbcCall(DataSource
the DataSource to use
dataSource
)

Constructor that takes one parameter with the JDBC DataSource to use when creating the underlying JdbcTemplate.

public
SimpleJdbcCall(JdbcTemplate
the JdbcTemplate to use
jdbcTemplate
)

Alternative Constructor that takes one parameter with the JdbcTemplate to be used.

Method Summary

Modifier and TypeMethod and Description
public SimpleJdbcCall
declareParameters(SqlParameter...
the parameters to use
sqlParameters
)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.declareParameters.

Specify one or more parameters if desired.

public Map<String, Object>
execute(Object...
optional array containing the in parameter values to be used in the call. Parameter values must be provided in the same order as the parameters are defined for the stored procedure.
args
)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.execute.

Execute the stored procedure and return a map of output params, keyed by name as in parameter declarations.

public Map<String, Object>
execute(Map<String, ?>
a Map containing the parameter values to be used in the call
args
)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.execute.

Execute the stored procedure and return a map of output params, keyed by name as in parameter declarations.

public Map<String, Object>
execute(SqlParameterSource
the SqlParameterSource containing the parameter values to be used in the call
parameterSource
)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.execute.

Execute the stored procedure and return a map of output params, keyed by name as in parameter declarations.

public <T> T
executeFunction(Class<T>
the type of the value to return
returnType
,
Object...
optional array containing the in parameter values to be used in the call. Parameter values must be provided in the same order as the parameters are defined for the stored procedure.
args
)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.executeFunction.

Execute the stored function and return the results obtained as an Object of the specified return type.

public <T> T
executeFunction(Class<T>
the type of the value to return
returnType
,
Map<String, ?>
a Map containing the parameter values to be used in the call
args
)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.executeFunction.

Execute the stored function and return the results obtained as an Object of the specified return type.

public <T> T
executeFunction(Class<T>
the type of the value to return
returnType
,
SqlParameterSource
the MapSqlParameterSource containing the parameter values to be used in the call
args
)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.executeFunction.

Execute the stored function and return the results obtained as an Object of the specified return type.

public <T> T
executeObject(Class<T>
the type of the value to return
returnType
,
Object...
optional array containing the in parameter values to be used in the call. Parameter values must be provided in the same order as the parameters are defined for the stored procedure.
args
)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.executeObject.

Execute the stored procedure and return the single out parameter as an Object of the specified return type.

public <T> T
executeObject(Class<T>
the type of the value to return
returnType
,
Map<String, ?>
a Map containing the parameter values to be used in the call
args
)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.executeObject.

Execute the stored procedure and return the single out parameter as an Object of the specified return type.

public <T> T
executeObject(Class<T>
the type of the value to return
returnType
,
SqlParameterSource
the MapSqlParameterSource containing the parameter values to be used in the call
args
)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.executeObject.

Execute the stored procedure and return the single out parameter as an Object of the specified return type.

public SimpleJdbcCall
returningResultSet(String
the name of the returned results and/or the name of the ref cursor parameter
parameterName
,
RowMapper<?>
the RowMapper implementation that will map the data returned for each row
rowMapper
)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.returningResultSet.

Used to specify when a ResultSet is returned by the stored procedure and you want it mapped by a RowMapper.

public SimpleJdbcCall
public SimpleJdbcCall
withCatalogName(String
the catalog or package name
catalogName
)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.withCatalogName.

Optionally, specify the name of the catalog that contins the stored procedure.

public SimpleJdbcCall
withFunctionName(String
the name of the stored function
functionName
)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.withFunctionName.

Specify the procedure name to be used - this implies that we will be calling a stored function.

public SimpleJdbcCall
withNamedBinding()

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.withNamedBinding.

Indicates that parameters should be bound by name.

public SimpleJdbcCall
withoutProcedureColumnMetaDataAccess()

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.withoutProcedureColumnMetaDataAccess.

Turn off any processing of parameter meta-data information obtained via JDBC.

public SimpleJdbcCall
withProcedureName(String
the name of the stored procedure
procedureName
)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.withProcedureName.

Specify the procedure name to be used - this implies that we will be calling a stored procedure.

public SimpleJdbcCall
withReturnValue()

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.withReturnValue.

Indicates the procedure's return value should be included in the results returned.

public SimpleJdbcCall
withSchemaName(String
the name of the schema
schemaName
)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.withSchemaName.

Optionally, specify the name of the schema that contins the stored procedure.

Inherited from org.springframework.jdbc.core.simple.AbstractJdbcCall:
addDeclaredParameteraddDeclaredRowMappercheckCompiledcompilecompileInternaldoExecutedoExecutedoExecutegetCallableStatementFactorygetCallParametersgetCallStringgetCatalogNamegetInParameterNamesgetJdbcTemplategetProcedureNamegetScalarOutParameterNamegetSchemaNameisCompiledisFunctionisNamedBindingisReturnValueRequiredmatchInParameterValuesWithCallParametersmatchInParameterValuesWithCallParametersonCompileInternalsetAccessCallParameterMetaDatasetCatalogNamesetFunctionsetInParameterNamessetNamedBindingsetProcedureNamesetReturnValueRequiredsetSchemaName

Constructor Detail

SimpleJdbcCallback to summary
public SimpleJdbcCall(DataSource dataSource)

Constructor that takes one parameter with the JDBC DataSource to use when creating the underlying JdbcTemplate.

Parameters
dataSource:DataSource

the DataSource to use

See Also
org.springframework.jdbc.core.JdbcTemplate#setDataSource
SimpleJdbcCallback to summary
public SimpleJdbcCall(JdbcTemplate jdbcTemplate)

Alternative Constructor that takes one parameter with the JdbcTemplate to be used.

Parameters
jdbcTemplate:JdbcTemplate

the JdbcTemplate to use

See Also
org.springframework.jdbc.core.JdbcTemplate#setDataSource

Method Detail

declareParametersback to summary
public SimpleJdbcCall declareParameters(SqlParameter... sqlParameters)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.declareParameters.

Doc from org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.declareParameters.

Specify one or more parameters if desired. These parameters will be supplemented with any parameter information retrieved from the database meta-data.

Note that only parameters declared as SqlParameter and SqlInOutParameter will be used to provide input values. This is different from the StoredProcedure class which - for backwards compatibility reasons - allows input values to be provided for parameters declared as SqlOutParameter.

Parameters
sqlParameters:SqlParameter[]

the parameters to use

Returns:SimpleJdbcCall

the instance of this SimpleJdbcCall

Annotations
@Override
executeback to summary
public Map<String, Object> execute(Object... args)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.execute.

Doc from org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.execute.

Execute the stored procedure and return a map of output params, keyed by name as in parameter declarations.

Parameters
args:Object[]

optional array containing the in parameter values to be used in the call. Parameter values must be provided in the same order as the parameters are defined for the stored procedure.

Returns:Map<String, Object>

a Map of output params

Annotations
@Override
executeback to summary
public Map<String, Object> execute(Map<String, ?> args)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.execute.

Doc from org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.execute.

Execute the stored procedure and return a map of output params, keyed by name as in parameter declarations.

Parameters
args:Map<String, ?>

a Map containing the parameter values to be used in the call

Returns:Map<String, Object>

a Map of output params

Annotations
@Override
executeback to summary
public Map<String, Object> execute(SqlParameterSource parameterSource)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.execute.

Doc from org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.execute.

Execute the stored procedure and return a map of output params, keyed by name as in parameter declarations.

Parameters
parameterSource:SqlParameterSource

the SqlParameterSource containing the parameter values to be used in the call

Returns:Map<String, Object>

a Map of output params

Annotations
@Override
executeFunctionback to summary
public <T> T executeFunction(Class<T> returnType, Object... args)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.executeFunction.

Doc from org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.executeFunction.

Execute the stored function and return the results obtained as an Object of the specified return type.

Parameters
returnType:Class<T>

the type of the value to return

args:Object[]

optional array containing the in parameter values to be used in the call. Parameter values must be provided in the same order as the parameters are defined for the stored procedure.

Annotations
@Override
@SuppressWarnings:unchecked
executeFunctionback to summary
public <T> T executeFunction(Class<T> returnType, Map<String, ?> args)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.executeFunction.

Doc from org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.executeFunction.

Execute the stored function and return the results obtained as an Object of the specified return type.

Parameters
returnType:Class<T>

the type of the value to return

args:Map<String, ?>

a Map containing the parameter values to be used in the call

Annotations
@Override
@SuppressWarnings:unchecked
executeFunctionback to summary
public <T> T executeFunction(Class<T> returnType, SqlParameterSource args)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.executeFunction.

Doc from org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.executeFunction.

Execute the stored function and return the results obtained as an Object of the specified return type.

Parameters
returnType:Class<T>

the type of the value to return

args:SqlParameterSource

the MapSqlParameterSource containing the parameter values to be used in the call

Annotations
@Override
@SuppressWarnings:unchecked
executeObjectback to summary
public <T> T executeObject(Class<T> returnType, Object... args)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.executeObject.

Doc from org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.executeObject.

Execute the stored procedure and return the single out parameter as an Object of the specified return type. In the case where there are multiple out parameters, the first one is returned and additional out parameters are ignored.

Parameters
returnType:Class<T>

the type of the value to return

args:Object[]

optional array containing the in parameter values to be used in the call. Parameter values must be provided in the same order as the parameters are defined for the stored procedure.

Annotations
@Override
@SuppressWarnings:unchecked
executeObjectback to summary
public <T> T executeObject(Class<T> returnType, Map<String, ?> args)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.executeObject.

Doc from org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.executeObject.

Execute the stored procedure and return the single out parameter as an Object of the specified return type. In the case where there are multiple out parameters, the first one is returned and additional out parameters are ignored.

Parameters
returnType:Class<T>

the type of the value to return

args:Map<String, ?>

a Map containing the parameter values to be used in the call

Annotations
@Override
@SuppressWarnings:unchecked
executeObjectback to summary
public <T> T executeObject(Class<T> returnType, SqlParameterSource args)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.executeObject.

Doc from org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.executeObject.

Execute the stored procedure and return the single out parameter as an Object of the specified return type. In the case where there are multiple out parameters, the first one is returned and additional out parameters are ignored.

Parameters
returnType:Class<T>

the type of the value to return

args:SqlParameterSource

the MapSqlParameterSource containing the parameter values to be used in the call

Annotations
@Override
@SuppressWarnings:unchecked
returningResultSetback to summary
public SimpleJdbcCall returningResultSet(String parameterName, RowMapper<?> rowMapper)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.returningResultSet.

Doc from org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.returningResultSet.

Used to specify when a ResultSet is returned by the stored procedure and you want it mapped by a RowMapper. The results will be returned using the parameter name specified. Multiple ResultSets must be declared in the correct order.

If the database you are using uses ref cursors then the name specified must match the name of the parameter declared for the procedure in the database.

Parameters
parameterName:String

the name of the returned results and/or the name of the ref cursor parameter

rowMapper:RowMapper<?>

the RowMapper implementation that will map the data returned for each row

Annotations
@Override
useInParameterNamesback to summary
public SimpleJdbcCall useInParameterNames(String... inParameterNames)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.useInParameterNames.

Doc from org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.useInParameterNames.

Not used yet.

Annotations
@Override
withCatalogNameback to summary
public SimpleJdbcCall withCatalogName(String catalogName)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.withCatalogName.

Doc from org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.withCatalogName.

Optionally, specify the name of the catalog that contins the stored procedure.

To provide consistency with the Oracle DatabaseMetaData, this is used to specify the package name if the procedure is declared as part of a package.

Parameters
catalogName:String

the catalog or package name

Returns:SimpleJdbcCall

the instance of this SimpleJdbcCall

Annotations
@Override
withFunctionNameback to summary
public SimpleJdbcCall withFunctionName(String functionName)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.withFunctionName.

Doc from org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.withFunctionName.

Specify the procedure name to be used - this implies that we will be calling a stored function.

Parameters
functionName:String

the name of the stored function

Returns:SimpleJdbcCall

the instance of this SimpleJdbcCall

Annotations
@Override
withNamedBindingback to summary
public SimpleJdbcCall withNamedBinding()

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.withNamedBinding.

Doc from org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.withNamedBinding.

Indicates that parameters should be bound by name.

Returns:SimpleJdbcCall

the instance of this SimpleJdbcCall

Annotations
@Override
withoutProcedureColumnMetaDataAccessback to summary
public SimpleJdbcCall withoutProcedureColumnMetaDataAccess()

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.withoutProcedureColumnMetaDataAccess.

Doc from org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.withoutProcedureColumnMetaDataAccess.

Turn off any processing of parameter meta-data information obtained via JDBC.

Returns:SimpleJdbcCall

the instance of this SimpleJdbcCall

Annotations
@Override
withProcedureNameback to summary
public SimpleJdbcCall withProcedureName(String procedureName)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.withProcedureName.

Doc from org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.withProcedureName.

Specify the procedure name to be used - this implies that we will be calling a stored procedure.

Parameters
procedureName:String

the name of the stored procedure

Returns:SimpleJdbcCall

the instance of this SimpleJdbcCall

Annotations
@Override
withReturnValueback to summary
public SimpleJdbcCall withReturnValue()

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.withReturnValue.

Doc from org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.withReturnValue.

Indicates the procedure's return value should be included in the results returned.

Returns:SimpleJdbcCall

the instance of this SimpleJdbcCall

Annotations
@Override
withSchemaNameback to summary
public SimpleJdbcCall withSchemaName(String schemaName)

Implements org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.withSchemaName.

Doc from org.springframework.jdbc.core.simple.SimpleJdbcCallOperations.withSchemaName.

Optionally, specify the name of the schema that contins the stored procedure.

Parameters
schemaName:String

the name of the schema

Returns:SimpleJdbcCall

the instance of this SimpleJdbcCall

Annotations
@Override