Top Description Methods
org.springframework.jdbc.core.namedparam

public Interface NamedParameterJdbcOperations

Known Direct Implementers
org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
Imports
java.util.List, .Map, java.util.stream.Stream, org.springframework.dao.DataAccessException, org.springframework.jdbc.core.JdbcOperations, .PreparedStatementCallback, .ResultSetExtractor, .RowCallbackHandler, .RowMapper, org.springframework.jdbc.support.KeyHolder, org.springframework.jdbc.support.rowset.SqlRowSet, org.springframework.lang.Nullable

Interface specifying a basic set of JDBC operations allowing the use of named parameters rather than the traditional '?' placeholders.

This is an alternative to the classic org.springframework.jdbc.core.JdbcOperations interface, implemented by NamedParameterJdbcTemplate. This interface is not often used directly, but provides a useful option to enhance testability, as it can easily be mocked or stubbed.

NOTE: As of 6.1, there is a unified JDBC access facade available in the form of org.springframework.jdbc.core.simple.JdbcClient. JdbcClient provides a fluent API style for common JDBC queries/updates with flexible use of indexed or named parameters. It delegates to JdbcOperations/NamedParameterJdbcOperations for actual execution.

Authors
Thomas Risberg, Juergen Hoeller
Since
2.0
See Also
NamedParameterJdbcTemplate, org.springframework.jdbc.core.JdbcOperations

Method Summary

Modifier and TypeMethod and Description
public int[]

Returns:

an array containing the numbers of rows affected by each update in the batch (may also contain special JDBC-defined negative values for affected rows such as java.sql.Statement#SUCCESS_NO_INFO/java.sql.Statement#EXECUTE_FAILED)
batchUpdate
(String
the SQL statement to execute
sql
,
SqlParameterSource[]
the array of SqlParameterSource containing the batch of arguments for the query
batchArgs
)

Execute a batch using the supplied SQL statement with the batch of supplied arguments.

public int[]

Returns:

an array containing the numbers of rows affected by each update in the batch (may also contain special JDBC-defined negative values for affected rows such as java.sql.Statement#SUCCESS_NO_INFO/java.sql.Statement#EXECUTE_FAILED)
batchUpdate
(String
the SQL statement to execute
sql
,
Map<String, ?>[]
the array of Maps containing the batch of arguments for the query
batchValues
)

Executes a batch using the supplied SQL statement with the batch of supplied arguments.

public int[]

Returns:

an array containing the numbers of rows affected by each update in the batch (may also contain special JDBC-defined negative values for affected rows such as java.sql.Statement#SUCCESS_NO_INFO/java.sql.Statement#EXECUTE_FAILED)
batchUpdate
(String
the SQL statement to execute
sql
,
SqlParameterSource[]
the array of SqlParameterSource containing the batch of arguments for the query
batchArgs
,
KeyHolder
a KeyHolder that will hold the generated keys
generatedKeyHolder
)

Execute a batch using the supplied SQL statement with the batch of supplied arguments, returning generated keys.

public int[]

Returns:

an array containing the numbers of rows affected by each update in the batch (may also contain special JDBC-defined negative values for affected rows such as java.sql.Statement#SUCCESS_NO_INFO/java.sql.Statement#EXECUTE_FAILED)
batchUpdate
(String
the SQL statement to execute
sql
,
SqlParameterSource[]
the array of SqlParameterSource containing the batch of arguments for the query
batchArgs
,
KeyHolder
a KeyHolder that will hold the generated keys
generatedKeyHolder
,
String[]
names of the columns that will have keys generated for them
keyColumnNames
)

Execute a batch using the supplied SQL statement with the batch of supplied arguments, returning generated keys.

public <T> T

Returns:

a result object returned by the action, or null
execute
(String
the SQL to execute
sql
,
SqlParameterSource
container of arguments to bind to the query
paramSource
,
PreparedStatementCallback<T>
callback object that specifies the action
action
)

Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement.

public <T> T

Returns:

a result object returned by the action, or null
execute
(String
the SQL to execute
sql
,
Map<String, ?>
map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
paramMap
,
PreparedStatementCallback<T>
callback object that specifies the action
action
)

Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement.

public <T> T

Returns:

a result object returned by the action, or null
execute
(String
the SQL to execute
sql
,
PreparedStatementCallback<T>
callback object that specifies the action
action
)

Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement.

public JdbcOperations
getJdbcOperations()

Expose the classic Spring JdbcTemplate to allow invocation of classic JDBC operations.

public <T> T

Returns:

an arbitrary result object, as returned by the ResultSetExtractor
query
(String
the SQL query to execute
sql
,
SqlParameterSource
container of arguments to bind to the query
paramSource
,
ResultSetExtractor<T>
object that will extract results
rse
)

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, reading the ResultSet with a ResultSetExtractor.

public <T> T

Returns:

an arbitrary result object, as returned by the ResultSetExtractor
query
(String
the SQL query to execute
sql
,
Map<String, ?>
map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
paramMap
,
ResultSetExtractor<T>
object that will extract results
rse
)

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, reading the ResultSet with a ResultSetExtractor.

public <T> T

Returns:

an arbitrary result object, as returned by the ResultSetExtractor
query
(String
the SQL query to execute
sql
,
ResultSetExtractor<T>
object that will extract results
rse
)

Query given SQL to create a prepared statement from SQL, reading the ResultSet with a ResultSetExtractor.

public void
query(String
the SQL query to execute
sql
,
SqlParameterSource
container of arguments to bind to the query
paramSource
,
RowCallbackHandler
object that will extract results, one row at a time
rch
)

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, reading the ResultSet on a per-row basis with a RowCallbackHandler.

public void
query(String
the SQL query to execute
sql
,
Map<String, ?>
map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
paramMap
,
RowCallbackHandler
object that will extract results, one row at a time
rch
)

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, reading the ResultSet on a per-row basis with a RowCallbackHandler.

public void
query(String
the SQL query to execute
sql
,
RowCallbackHandler
object that will extract results, one row at a time
rch
)

Query given SQL to create a prepared statement from SQL, reading the ResultSet on a per-row basis with a RowCallbackHandler.

public <T> List<T>

Returns:

the result List, containing mapped objects
query
(String
the SQL query to execute
sql
,
SqlParameterSource
container of arguments to bind to the query
paramSource
,
RowMapper<T>
object that will map one object per row
rowMapper
)

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping each row to a Java object via a RowMapper.

public <T> List<T>

Returns:

the result List, containing mapped objects
query
(String
the SQL query to execute
sql
,
Map<String, ?>
map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
paramMap
,
RowMapper<T>
object that will map one object per row
rowMapper
)

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping each row to a Java object via a RowMapper.

public <T> List<T>

Returns:

the result List, containing mapped objects
query
(String
the SQL query to execute
sql
,
RowMapper<T>
object that will map one object per row
rowMapper
)

Query given SQL to create a prepared statement from SQL, mapping each row to a Java object via a RowMapper.

public <T> List<T>

Returns:

a List of objects that match the specified element type
queryForList
(String
the SQL query to execute
sql
,
SqlParameterSource
container of arguments to bind to the query
paramSource
,
Class<T>
the required type of element in the result list (for example, Integer.class)
elementType
)

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.

public <T> List<T>

Returns:

a List of objects that match the specified element type
queryForList
(String
the SQL query to execute
sql
,
Map<String, ?>
map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
paramMap
,
Class<T>
the required type of element in the result list (for example, Integer.class)
elementType
)

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.

public List<Map<String, Object>>

Returns:

a List that contains a Map per row
queryForList
(String
the SQL query to execute
sql
,
SqlParameterSource
container of arguments to bind to the query
paramSource
)

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.

public List<Map<String, Object>>

Returns:

a List that contains a Map per row
queryForList
(String
the SQL query to execute
sql
,
Map<String, ?>
map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
paramMap
)

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.

public Map<String, Object>

Returns:

the result Map (one entry for each column, using the column name as the key)
queryForMap
(String
the SQL query to execute
sql
,
SqlParameterSource
container of arguments to bind to the query
paramSource
)

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result Map.

public Map<String, Object>

Returns:

the result Map (one entry for each column, using the column name as the key)
queryForMap
(String
the SQL query to execute
sql
,
Map<String, ?>
map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
paramMap
)

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result Map.

public <T> T

Returns:

the single mapped object (may be null if the given RowMapper returned null)
queryForObject
(String
the SQL query to execute
sql
,
SqlParameterSource
container of arguments to bind to the query
paramSource
,
RowMapper<T>
object that will map one object per row
rowMapper
)

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping a single result row to a Java object via a RowMapper.

public <T> T

Returns:

the single mapped object (may be null if the given RowMapper returned null)
queryForObject
(String
the SQL query to execute
sql
,
Map<String, ?>
map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
paramMap
,
RowMapper<T>
object that will map one object per row
rowMapper
)

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping a single result row to a Java object via a RowMapper.

public <T> T

Returns:

the result object of the required type, or null in case of SQL NULL
queryForObject
(String
the SQL query to execute
sql
,
SqlParameterSource
container of arguments to bind to the query
paramSource
,
Class<T>
the type that the result object is expected to match
requiredType
)

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result object.

public <T> T

Returns:

the result object of the required type, or null in case of SQL NULL
queryForObject
(String
the SQL query to execute
sql
,
Map<String, ?>
map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
paramMap
,
Class<T>
the type that the result object is expected to match
requiredType
)

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result object.

public SqlRowSet

Returns:

an SqlRowSet representation (possibly a wrapper around a javax.sql.rowset.CachedRowSet)
queryForRowSet
(String
the SQL query to execute
sql
,
SqlParameterSource
container of arguments to bind to the query
paramSource
)

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting an SqlRowSet.

public SqlRowSet

Returns:

an SqlRowSet representation (possibly a wrapper around a javax.sql.rowset.CachedRowSet)
queryForRowSet
(String
the SQL query to execute
sql
,
Map<String, ?>
map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
paramMap
)

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting an SqlRowSet.

public <T> Stream<T>

Returns:

the result Stream, containing mapped objects, needing to be closed once fully processed (e.g. through a try-with-resources clause)
queryForStream
(String
the SQL query to execute
sql
,
SqlParameterSource
container of arguments to bind to the query
paramSource
,
RowMapper<T>
object that will map one object per row
rowMapper
)

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping each row to a Java object via a RowMapper, and turning it into an iterable and closeable Stream.

public <T> Stream<T>

Returns:

the result Stream, containing mapped objects, needing to be closed once fully processed (e.g. through a try-with-resources clause)
queryForStream
(String
the SQL query to execute
sql
,
Map<String, ?>
map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
paramMap
,
RowMapper<T>
object that will map one object per row
rowMapper
)

Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, mapping each row to a Java object via a RowMapper, and turning it into an iterable and closeable Stream.

public int

Returns:

the number of rows affected
update
(String
the SQL containing named parameters
sql
,
SqlParameterSource
container of arguments and SQL types to bind to the query
paramSource
)

Issue an update via a prepared statement, binding the given arguments.

public int

Returns:

the number of rows affected
update
(String
the SQL containing named parameters
sql
,
Map<String, ?>
map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
paramMap
)

Issue an update via a prepared statement, binding the given arguments.

public int

Returns:

the number of rows affected
update
(String
the SQL containing named parameters
sql
,
SqlParameterSource
container of arguments and SQL types to bind to the query
paramSource
,
KeyHolder
a KeyHolder that will hold the generated keys
generatedKeyHolder
)

Issue an update via a prepared statement, binding the given arguments, returning generated keys.

public int

Returns:

the number of rows affected
update
(String
the SQL containing named parameters
sql
,
SqlParameterSource
container of arguments and SQL types to bind to the query
paramSource
,
KeyHolder
a KeyHolder that will hold the generated keys
generatedKeyHolder
,
String[]
names of the columns that will have keys generated for them
keyColumnNames
)

Issue an update via a prepared statement, binding the given arguments, returning generated keys.