|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.jdbc.core.simple.SimpleJdbcTemplate
public class SimpleJdbcTemplate
Java-5-based convenience wrapper for the classic Spring
JdbcTemplate
,
taking advantage of varargs and autoboxing, and exposing only the most
commonly required operations in order to simplify JdbcTemplate usage.
Use the getJdbcOperations()
method (or a straight JdbcTemplate)
if you need to invoke less commonly used template methods. This includes
any methods specifying SQL types, methods using less commonly used callbacks
such as RowCallbackHandler, updates with PreparedStatementSetters rather than
argument arrays, and stored procedures as well as batch operations.
ParameterizedRowMapper
,
SimpleJdbcDaoSupport
,
JdbcTemplate
Constructor Summary | |
---|---|
SimpleJdbcTemplate(DataSource dataSource)
Create a new SimpleJdbcTemplate for the given DataSource. |
|
SimpleJdbcTemplate(JdbcOperations classicJdbcTemplate)
Create a new SimpleJdbcTemplate for the given classic Spring JdbcTemplate. |
Method Summary | ||
---|---|---|
JdbcOperations |
getJdbcOperations()
Expose the classic Spring JdbcTemplate to allow invocation of less commonly used methods. |
|
|
query(String sql,
ParameterizedRowMapper<T> rm,
Object... args)
Query for a List of Objects of type T using
the supplied ParameterizedRowMapper to the query results to the object. |
|
int |
queryForInt(String sql,
Object... args)
Query for an int passing in a SQL query and a variable
number of arguments. |
|
List<Map<String,Object>> |
queryForList(String sql,
Object... args)
Execute the supplied query with the (optional) supplied arguments. |
|
long |
queryForLong(String sql,
Object... args)
Query for an long passing in a SQL query and a variable
number of arguments. |
|
Map<String,Object> |
queryForMap(String sql,
Object... args)
Execute the supplied query with the (optional) supplied arguments. |
|
|
queryForObject(String sql,
Class<T> requiredType,
Object... args)
Query for an object of type T identified by the supplied @Class . |
|
|
queryForObject(String sql,
ParameterizedRowMapper<T> rm,
Object... args)
Query for an object of type T using the supplied
ParameterizedRowMapper to the query results to the object. |
|
int |
update(String sql,
Object... args)
Executes the supplied SQL statement with (optional) supplied arguments. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SimpleJdbcTemplate(DataSource dataSource)
Creates a classic Spring JdbcTemplate and wraps it.
dataSource
- the JDBC DataSource to accesspublic SimpleJdbcTemplate(JdbcOperations classicJdbcTemplate)
classicJdbcTemplate
- the classic Spring JdbcTemplate to wrapMethod Detail |
---|
public JdbcOperations getJdbcOperations()
getJdbcOperations
in interface SimpleJdbcOperations
public int queryForInt(String sql, Object... args) throws DataAccessException
SimpleJdbcOperations
int
passing in a SQL query and a variable
number of arguments.
queryForInt
in interface SimpleJdbcOperations
DataAccessException
public long queryForLong(String sql, Object... args) throws DataAccessException
SimpleJdbcOperations
long
passing in a SQL query and a variable
number of arguments.
queryForLong
in interface SimpleJdbcOperations
DataAccessException
public <T> T queryForObject(String sql, Class<T> requiredType, Object... args) throws DataAccessException
SimpleJdbcOperations
T
identified by the supplied @Class
.
queryForObject
in interface SimpleJdbcOperations
sql
- the SQL query to run.requiredType
- the required type of the return value.args
- the args for the query.
DataAccessException
JdbcOperations.queryForObject(String, Class)
,
JdbcOperations.queryForObject(String, Object[], Class)
public <T> T queryForObject(String sql, ParameterizedRowMapper<T> rm, Object... args) throws DataAccessException
SimpleJdbcOperations
T
using the supplied
ParameterizedRowMapper
to the query results to the object.
queryForObject
in interface SimpleJdbcOperations
sql
- the SQL query to run.rm
- the @ParameterizedRowMapper
to use for result mappingargs
- the args for the query.
DataAccessException
JdbcOperations.queryForObject(String, org.springframework.jdbc.core.RowMapper)
,
JdbcOperations.queryForObject(String, Object[], org.springframework.jdbc.core.RowMapper)
public <T> List<T> query(String sql, ParameterizedRowMapper<T> rm, Object... args) throws DataAccessException
SimpleJdbcOperations
List
of Objects
of type T
using
the supplied ParameterizedRowMapper
to the query results to the object.
query
in interface SimpleJdbcOperations
sql
- the SQL query to run.rm
- the @ParameterizedRowMapper
to use for result mappingargs
- the args for the query.
DataAccessException
JdbcOperations.queryForObject(String, org.springframework.jdbc.core.RowMapper)
,
JdbcOperations.queryForObject(String, Object[], org.springframework.jdbc.core.RowMapper)
public Map<String,Object> queryForMap(String sql, Object... args) throws DataAccessException
SimpleJdbcOperations
The query is expected to be a single row query; the result row will be mapped to a Map (one entry for each column, using the column name as the key).
queryForMap
in interface SimpleJdbcOperations
public List<Map<String,Object>> queryForList(String sql, Object... args) throws DataAccessException
SimpleJdbcOperations
Each element in the returned List
is constructed as a Map
as described in SimpleJdbcOperations.queryForMap(java.lang.String, java.lang.Object...)
queryForList
in interface SimpleJdbcOperations
public int update(String sql, Object... args) throws DataAccessException
SimpleJdbcOperations
update
in interface SimpleJdbcOperations
DataAccessException
JdbcOperations.update(String)
,
JdbcOperations.update(String, Object[])
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |