Package org.springframework.jdbc.core.namedparam

# Class NamedParameterJdbcTemplate

java.lang.Object
org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate

All Implemented Interfaces:
  `NamedParameterJdbcOperations`

public class NamedParameterJdbcTemplate extends Object implements NamedParameterJdbcOperations
Template class with a basic set of JDBC operations, allowing the use of named parameters rather than traditional '?' placeholders.

This class delegates to a wrapped `JdbcTemplate` once the substitution from named parameters to JDBC style '?' placeholders is done at execution time. It also allows for expanding a `List` of values to the appropriate number of placeholders.

An instance of this template class is thread-safe once configured. The underlying `JdbcTemplate` is exposed to allow for convenient access to the traditional `JdbcTemplate` methods.

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

Since:
  2.0
Author:
  Thomas Risberg, Juergen Hoeller
See Also:
  - `NamedParameterJdbcOperations`
  - `SqlParameterSource`
  - `ResultSetExtractor`
  - `RowCallbackHandler`
  - `RowMapper`
  - `JdbcTemplate`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`DEFAULT_CACHE_LIMIT`
Default maximum number of entries for this template's SQL cache: 256.

## Constructor Summary

Constructors
Constructor
Description
`NamedParameterJdbcTemplate(DataSource dataSource)`
Create a new NamedParameterJdbcTemplate for the given `DataSource`.
`NamedParameterJdbcTemplate(JdbcOperations classicJdbcTemplate)`
Create a new NamedParameterJdbcTemplate for the given classic Spring `JdbcTemplate`.

## Method Summary

Modifier and Type
Method
Description
`int[]`
`batchUpdate(String sql, Map<String,?>[] batchValues)`
Executes a batch using the supplied SQL statement with the batch of supplied arguments.
`int[]`
`batchUpdate(String sql, SqlParameterSource[] batchArgs)`
Execute a batch using the supplied SQL statement with the batch of supplied arguments.
`int[]`
`batchUpdate(String sql, SqlParameterSource[] batchArgs, KeyHolder generatedKeyHolder)`
Execute a batch using the supplied SQL statement with the batch of supplied arguments, returning generated keys.
`int[]`
`batchUpdate(String sql, SqlParameterSource[] batchArgs, KeyHolder generatedKeyHolder, String[] keyColumnNames)`
Execute a batch using the supplied SQL statement with the batch of supplied arguments, returning generated keys.
`<T> T`
`execute(String sql, Map<String,?> paramMap, PreparedStatementCallback<T> action)`
Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement.
`<T> T`
`execute(String sql, SqlParameterSource paramSource, PreparedStatementCallback<T> action)`
Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement.
`<T> T`
`execute(String sql, PreparedStatementCallback<T> action)`
Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement.
`int`
`getCacheLimit()`
Return the maximum number of entries for this template's SQL cache.
`JdbcOperations`
`getJdbcOperations()`
Expose the classic Spring JdbcTemplate operations to allow invocation of less commonly used methods.
`JdbcTemplate`
`getJdbcTemplate()`
Expose the classic Spring `JdbcTemplate` itself, if available, in particular for passing it on to other `JdbcTemplate` consumers.
`protected ParsedSql`
`getParsedSql(String sql)`
Obtain a parsed representation of the given SQL statement.
`protected PreparedStatementCreator`
`getPreparedStatementCreator(String sql, SqlParameterSource paramSource)`
Build a `PreparedStatementCreator` based on the given SQL and named parameters.
`protected PreparedStatementCreator`
`getPreparedStatementCreator(String sql, SqlParameterSource paramSource, Consumer<PreparedStatementCreatorFactory> customizer)`
Build a `PreparedStatementCreator` based on the given SQL and named parameters.
`protected PreparedStatementCreatorFactory`
`getPreparedStatementCreatorFactory(ParsedSql parsedSql, SqlParameterSource paramSource)`
Build a `PreparedStatementCreatorFactory` based on the given SQL and named parameters.
`<T> T`
`query(String sql, Map<String,?> paramMap, ResultSetExtractor<T> 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.
`void`
`query(String sql, Map<String,?> paramMap, RowCallbackHandler 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.
`<T> List<T>`
`query(String sql, Map<String,?> paramMap, RowMapper<T> 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.
`<T> T`
`query(String sql, SqlParameterSource paramSource, ResultSetExtractor<T> 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.
`void`
`query(String sql, SqlParameterSource paramSource, RowCallbackHandler 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.
`<T> List<T>`
`query(String sql, SqlParameterSource paramSource, RowMapper<T> 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.
`<T> T`
`query(String sql, ResultSetExtractor<T> rse)`
Query given SQL to create a prepared statement from SQL, reading the ResultSet with a ResultSetExtractor.
`void`
`query(String sql, RowCallbackHandler rch)`
Query given SQL to create a prepared statement from SQL, reading the ResultSet on a per-row basis with a RowCallbackHandler.
`<T> List<T>`
`query(String sql, RowMapper<T> rowMapper)`
Query given SQL to create a prepared statement from SQL, mapping each row to a Java object via a RowMapper.
`List<Map<String,Object>>`
`queryForList(String sql, Map<String,?> 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.
`<T> List<T>`
`queryForList(String sql, Map<String,?> paramMap, Class<T> 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.
`List<Map<String,Object>>`
`queryForList(String sql, SqlParameterSource 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.
`<T> List<T>`
`queryForList(String sql, SqlParameterSource paramSource, Class<T> 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.
`Map<String,Object>`
`queryForMap(String sql, Map<String,?> 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.
`Map<String,Object>`
`queryForMap(String sql, SqlParameterSource 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.
`<T> T`
`queryForObject(String sql, Map<String,?> paramMap, Class<T> 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.
`<T> T`
`queryForObject(String sql, Map<String,?> paramMap, RowMapper<T> 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.
`<T> T`
`queryForObject(String sql, SqlParameterSource paramSource, Class<T> 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.
`<T> T`
`queryForObject(String sql, SqlParameterSource paramSource, RowMapper<T> 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.
`SqlRowSet`
`queryForRowSet(String sql, Map<String,?> paramMap)`
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting an SqlRowSet.
`SqlRowSet`
`queryForRowSet(String sql, SqlParameterSource paramSource)`
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting an SqlRowSet.
`<T> Stream<T>`
`queryForStream(String sql, Map<String,?> paramMap, RowMapper<T> 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.
`<T> Stream<T>`
`queryForStream(String sql, SqlParameterSource paramSource, RowMapper<T> 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.
`void`
`setCacheLimit(int cacheLimit)`
Specify the maximum number of entries for this template's SQL cache.
`int`
`update(String sql, Map<String,?> paramMap)`
Issue an update via a prepared statement, binding the given arguments.
`int`
`update(String sql, SqlParameterSource paramSource)`
Issue an update via a prepared statement, binding the given arguments.
`int`
`update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder)`
Issue an update via a prepared statement, binding the given arguments, returning generated keys.
`int`
`update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder, String[] keyColumnNames)`
Issue an update via a prepared statement, binding the given arguments, returning generated keys.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### DEFAULT_CACHE_LIMIT

public static final int DEFAULT_CACHE_LIMIT
Default maximum number of entries for this template's SQL cache: 256.

See Also:
  - Constant Field Values

## Constructor Details

### NamedParameterJdbcTemplate

public NamedParameterJdbcTemplate(DataSource dataSource)
Create a new NamedParameterJdbcTemplate for the given `DataSource`.

Creates a classic Spring `JdbcTemplate` and wraps it.

Parameters:
  `dataSource` - the JDBC DataSource to access

### NamedParameterJdbcTemplate

public NamedParameterJdbcTemplate(JdbcOperations classicJdbcTemplate)
Create a new NamedParameterJdbcTemplate for the given classic Spring `JdbcTemplate`.

Parameters:
  `classicJdbcTemplate` - the classic Spring JdbcTemplate to wrap

## Method Details

### getJdbcOperations

public JdbcOperations getJdbcOperations()
Expose the classic Spring JdbcTemplate operations to allow invocation of less commonly used methods.

Specified by:
  `getJdbcOperations` in interface `NamedParameterJdbcOperations`

### getJdbcTemplate

public JdbcTemplate getJdbcTemplate()
Expose the classic Spring `JdbcTemplate` itself, if available, in particular for passing it on to other `JdbcTemplate` consumers.

If sufficient for the purposes at hand, `getJdbcOperations()` is recommended over this variant.

Since:
  5.0.3

### setCacheLimit

public void setCacheLimit(int cacheLimit)
Specify the maximum number of entries for this template's SQL cache. Default is 256. 0 indicates no caching, always parsing each statement.

### getCacheLimit

public int getCacheLimit()
Return the maximum number of entries for this template's SQL cache.

### execute

@Nullable public <T> T execute(String sql, SqlParameterSource paramSource, PreparedStatementCallback<T> action) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement. This allows for implementing arbitrary data access operations on a single Statement, within Spring's managed JDBC environment: that is, participating in Spring-managed transactions and converting JDBC SQLExceptions into Spring's DataAccessException hierarchy.

The callback action can return a result object, for example a domain object or a collection of domain objects.

Specified by:
  `execute` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL to execute
  `paramSource` - container of arguments to bind to the query
  `action` - callback object that specifies the action
Returns:
  a result object returned by the action, or `null`
Throws:
  `org.springframework.dao.DataAccessException` - if there is any problem

### execute

@Nullable public <T> T execute(String sql, Map<String,?> paramMap, PreparedStatementCallback<T> action) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement. This allows for implementing arbitrary data access operations on a single Statement, within Spring's managed JDBC environment: that is, participating in Spring-managed transactions and converting JDBC SQLExceptions into Spring's DataAccessException hierarchy.

The callback action can return a result object, for example a domain object or a collection of domain objects.

Specified by:
  `execute` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL to execute
  `paramMap` - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
  `action` - callback object that specifies the action
Returns:
  a result object returned by the action, or `null`
Throws:
  `org.springframework.dao.DataAccessException` - if there is any problem

### execute

@Nullable public <T> T execute(String sql, PreparedStatementCallback<T> action) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement. This allows for implementing arbitrary data access operations on a single Statement, within Spring's managed JDBC environment: that is, participating in Spring-managed transactions and converting JDBC SQLExceptions into Spring's DataAccessException hierarchy.

The callback action can return a result object, for example a domain object or a collection of domain objects.

Specified by:
  `execute` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL to execute
  `action` - callback object that specifies the action
Returns:
  a result object returned by the action, or `null`
Throws:
  `org.springframework.dao.DataAccessException` - if there is any problem

### query

@Nullable public <T> T query(String sql, SqlParameterSource paramSource, ResultSetExtractor<T> rse) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
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.

Specified by:
  `query` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `paramSource` - container of arguments to bind to the query
  `rse` - object that will extract results
Returns:
  an arbitrary result object, as returned by the ResultSetExtractor
Throws:
  `org.springframework.dao.DataAccessException` - if the query fails

### query

@Nullable public <T> T query(String sql, Map<String,?> paramMap, ResultSetExtractor<T> rse) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
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.

Specified by:
  `query` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `paramMap` - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
  `rse` - object that will extract results
Returns:
  an arbitrary result object, as returned by the ResultSetExtractor
Throws:
  `org.springframework.dao.DataAccessException` - if the query fails

### query

@Nullable public <T> T query(String sql, ResultSetExtractor<T> rse) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
Query given SQL to create a prepared statement from SQL, reading the ResultSet with a ResultSetExtractor.

Note: In contrast to the JdbcOperations method with the same signature, this query variant always uses a PreparedStatement. It is effectively equivalent to a query call with an empty parameter Map.

Specified by:
  `query` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `rse` - object that will extract results
Returns:
  an arbitrary result object, as returned by the ResultSetExtractor
Throws:
  `org.springframework.dao.DataAccessException` - if the query fails

### query

public void query(String sql, SqlParameterSource paramSource, RowCallbackHandler rch) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
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.

Specified by:
  `query` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `paramSource` - container of arguments to bind to the query
  `rch` - object that will extract results, one row at a time
Throws:
  `org.springframework.dao.DataAccessException` - if the query fails

### query

public void query(String sql, Map<String,?> paramMap, RowCallbackHandler rch) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
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.

Specified by:
  `query` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `paramMap` - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
  `rch` - object that will extract results, one row at a time
Throws:
  `org.springframework.dao.DataAccessException` - if the query fails

### query

public void query(String sql, RowCallbackHandler rch) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
Query given SQL to create a prepared statement from SQL, reading the ResultSet on a per-row basis with a RowCallbackHandler.

Note: In contrast to the JdbcOperations method with the same signature, this query variant always uses a PreparedStatement. It is effectively equivalent to a query call with an empty parameter Map.

Specified by:
  `query` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `rch` - object that will extract results, one row at a time
Throws:
  `org.springframework.dao.DataAccessException` - if the query fails

### query

public <T> List<T> query(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
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.

Specified by:
  `query` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `paramSource` - container of arguments to bind to the query
  `rowMapper` - object that will map one object per row
Returns:
  the result List, containing mapped objects
Throws:
  `org.springframework.dao.DataAccessException` - if the query fails

### query

public <T> List<T> query(String sql, Map<String,?> paramMap, RowMapper<T> rowMapper) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
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.

Specified by:
  `query` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `paramMap` - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
  `rowMapper` - object that will map one object per row
Returns:
  the result List, containing mapped objects
Throws:
  `org.springframework.dao.DataAccessException` - if the query fails

### query

public <T> List<T> query(String sql, RowMapper<T> rowMapper) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
Query given SQL to create a prepared statement from SQL, mapping each row to a Java object via a RowMapper.

Note: In contrast to the JdbcOperations method with the same signature, this query variant always uses a PreparedStatement. It is effectively equivalent to a query call with an empty parameter Map.

Specified by:
  `query` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `rowMapper` - object that will map one object per row
Returns:
  the result List, containing mapped objects
Throws:
  `org.springframework.dao.DataAccessException` - if the query fails

### queryForStream

public <T> Stream<T> queryForStream(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
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.

Specified by:
  `queryForStream` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `paramSource` - container of arguments to bind to the query
  `rowMapper` - object that will map one object per row
Returns:
  the result Stream, containing mapped objects, needing to be closed once fully processed (for example, through a try-with-resources clause)
Throws:
  `org.springframework.dao.DataAccessException` - if the query fails

### queryForStream

public <T> Stream<T> queryForStream(String sql, Map<String,?> paramMap, RowMapper<T> rowMapper) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
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.

Specified by:
  `queryForStream` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `paramMap` - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
  `rowMapper` - object that will map one object per row
Returns:
  the result Stream, containing mapped objects, needing to be closed once fully processed (for example, through a try-with-resources clause)
Throws:
  `org.springframework.dao.DataAccessException` - if the query fails

### queryForObject

@Nullable public <T> T queryForObject(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
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.

Specified by:
  `queryForObject` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `paramSource` - container of arguments to bind to the query
  `rowMapper` - object that will map one object per row
Returns:
  the single mapped object (may be `null` if the given `RowMapper` returned null)
Throws:
  `org.springframework.dao.IncorrectResultSizeDataAccessException` - if the query does not return exactly one row
  `org.springframework.dao.DataAccessException` - if the query fails

### queryForObject

@Nullable public <T> T queryForObject(String sql, Map<String,?> paramMap, RowMapper<T> rowMapper) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
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.

Specified by:
  `queryForObject` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `paramMap` - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
  `rowMapper` - object that will map one object per row
Returns:
  the single mapped object (may be `null` if the given `RowMapper` returned null)
Throws:
  `org.springframework.dao.IncorrectResultSizeDataAccessException` - if the query does not return exactly one row
  `org.springframework.dao.DataAccessException` - if the query fails

### queryForObject

@Nullable public <T> T queryForObject(String sql, SqlParameterSource paramSource, Class<T> requiredType) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result object.

The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.

Specified by:
  `queryForObject` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `paramSource` - container of arguments to bind to the query
  `requiredType` - the type that the result object is expected to match
Returns:
  the result object of the required type, or `null` in case of SQL NULL
Throws:
  `org.springframework.dao.IncorrectResultSizeDataAccessException` - if the query does not return exactly one row
  `IncorrectResultSetColumnCountException` - if the query does not return a row containing a single column
  `org.springframework.dao.DataAccessException` - if the query fails
See Also:
  - `JdbcTemplate.queryForObject(String, Class)`
  - `SingleColumnRowMapper`

### queryForObject

@Nullable public <T> T queryForObject(String sql, Map<String,?> paramMap, Class<T> requiredType) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result object.

The query is expected to be a single row/single column query; the returned result will be directly mapped to the corresponding object type.

Specified by:
  `queryForObject` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `paramMap` - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
  `requiredType` - the type that the result object is expected to match
Returns:
  the result object of the required type, or `null` in case of SQL NULL
Throws:
  `org.springframework.dao.IncorrectResultSizeDataAccessException` - if the query does not return exactly one row
  `IncorrectResultSetColumnCountException` - if the query does not return a row containing a single column
  `org.springframework.dao.DataAccessException` - if the query fails
See Also:
  - `JdbcTemplate.queryForObject(String, Class)`

### queryForMap

public Map<String,Object> queryForMap(String sql, SqlParameterSource paramSource) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result Map.

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).

Specified by:
  `queryForMap` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `paramSource` - container of arguments to bind to the query
Returns:
  the result Map (one entry for each column, using the column name as the key)
Throws:
  `org.springframework.dao.IncorrectResultSizeDataAccessException` - if the query does not return exactly one row
  `org.springframework.dao.DataAccessException` - if the query fails
See Also:
  - `JdbcTemplate.queryForMap(String)`
  - `ColumnMapRowMapper`

### queryForMap

public Map<String,Object> queryForMap(String sql, Map<String,?> paramMap) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result Map. The queryForMap() methods defined by this interface are appropriate when you don't have a domain model. Otherwise, consider using one of the queryForObject() methods.

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).

Specified by:
  `queryForMap` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `paramMap` - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
Returns:
  the result Map (one entry for each column, using the column name as the key)
Throws:
  `org.springframework.dao.IncorrectResultSizeDataAccessException` - if the query does not return exactly one row
  `org.springframework.dao.DataAccessException` - if the query fails
See Also:
  - `JdbcTemplate.queryForMap(String)`
  - `ColumnMapRowMapper`

### queryForList

public <T> List<T> queryForList(String sql, SqlParameterSource paramSource, Class<T> elementType) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.

The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.

Specified by:
  `queryForList` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `paramSource` - container of arguments to bind to the query
  `elementType` - the required type of element in the result list (for example, `Integer.class`)
Returns:
  a List of objects that match the specified element type
Throws:
  `org.springframework.dao.DataAccessException` - if the query fails
See Also:
  - `JdbcTemplate.queryForList(String, Class)`
  - `SingleColumnRowMapper`

### queryForList

public <T> List<T> queryForList(String sql, Map<String,?> paramMap, Class<T> elementType) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.

The results will be mapped to a List (one entry for each row) of result objects, each of them matching the specified element type.

Specified by:
  `queryForList` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `paramMap` - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
  `elementType` - the required type of element in the result list (for example, `Integer.class`)
Returns:
  a List of objects that match the specified element type
Throws:
  `org.springframework.dao.DataAccessException` - if the query fails
See Also:
  - `JdbcTemplate.queryForList(String, Class)`
  - `SingleColumnRowMapper`

### queryForList

public List<Map<String,Object>> queryForList(String sql, SqlParameterSource paramSource) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.

The results will be mapped to a List (one entry for each row) of Maps (one entry for each column, using the column name as the key). Each element in the list will be of the form returned by this interface's `queryForMap` methods.

Specified by:
  `queryForList` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `paramSource` - container of arguments to bind to the query
Returns:
  a List that contains a Map per row
Throws:
  `org.springframework.dao.DataAccessException` - if the query fails
See Also:
  - `JdbcTemplate.queryForList(String)`

### queryForList

public List<Map<String,Object>> queryForList(String sql, Map<String,?> paramMap) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a result list.

The results will be mapped to a List (one entry for each row) of Maps (one entry for each column, using the column name as the key). Each element in the list will be of the form returned by this interface's `queryForMap` methods.

Specified by:
  `queryForList` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `paramMap` - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
Returns:
  a List that contains a Map per row
Throws:
  `org.springframework.dao.DataAccessException` - if the query fails
See Also:
  - `JdbcTemplate.queryForList(String)`

### queryForRowSet

public SqlRowSet queryForRowSet(String sql, SqlParameterSource paramSource) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting an SqlRowSet.

The results will be mapped to an SqlRowSet which holds the data in a disconnected fashion. This wrapper will translate any SQLExceptions thrown.

Note that, for the default implementation, JDBC RowSet support needs to be available at runtime: by default, a standard JDBC `CachedRowSet` is used.

Specified by:
  `queryForRowSet` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `paramSource` - container of arguments to bind to the query
Returns:
  an SqlRowSet representation (possibly a wrapper around a `javax.sql.rowset.CachedRowSet`)
Throws:
  `org.springframework.dao.DataAccessException` - if there is any problem executing the query
See Also:
  - `JdbcTemplate.queryForRowSet(String)`
  - `SqlRowSetResultSetExtractor`
  - `CachedRowSet`

### queryForRowSet

public SqlRowSet queryForRowSet(String sql, Map<String,?> paramMap) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting an SqlRowSet.

The results will be mapped to an SqlRowSet which holds the data in a disconnected fashion. This wrapper will translate any SQLExceptions thrown.

Note that, for the default implementation, JDBC RowSet support needs to be available at runtime: by default, a standard JDBC `CachedRowSet` is used.

Specified by:
  `queryForRowSet` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL query to execute
  `paramMap` - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
Returns:
  an SqlRowSet representation (possibly a wrapper around a `javax.sql.rowset.CachedRowSet`)
Throws:
  `org.springframework.dao.DataAccessException` - if there is any problem executing the query
See Also:
  - `JdbcTemplate.queryForRowSet(String)`
  - `SqlRowSetResultSetExtractor`
  - `CachedRowSet`

### update

public int update(String sql, SqlParameterSource paramSource) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
Issue an update via a prepared statement, binding the given arguments.

Specified by:
  `update` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL containing named parameters
  `paramSource` - container of arguments and SQL types to bind to the query
Returns:
  the number of rows affected
Throws:
  `org.springframework.dao.DataAccessException` - if there is any problem issuing the update

### update

public int update(String sql, Map<String,?> paramMap) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
Issue an update via a prepared statement, binding the given arguments.

Specified by:
  `update` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL containing named parameters
  `paramMap` - map of parameters to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
Returns:
  the number of rows affected
Throws:
  `org.springframework.dao.DataAccessException` - if there is any problem issuing the update

### update

public int update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
Issue an update via a prepared statement, binding the given arguments, returning generated keys.

This method requires support for generated keys in the JDBC driver.

Specified by:
  `update` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL containing named parameters
  `paramSource` - container of arguments and SQL types to bind to the query
  `generatedKeyHolder` - a `KeyHolder` that will hold the generated keys
Returns:
  the number of rows affected
Throws:
  `org.springframework.dao.DataAccessException` - if there is any problem issuing the update
See Also:
  - `MapSqlParameterSource`
  - `GeneratedKeyHolder`
  - `DatabaseMetaData.supportsGetGeneratedKeys()`

### update

public int update(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder, @Nullable String[] keyColumnNames) throws org.springframework.dao.DataAccessException
Description copied from interface: `NamedParameterJdbcOperations`
Issue an update via a prepared statement, binding the given arguments, returning generated keys.

This method requires support for generated keys in the JDBC driver.

Specified by:
  `update` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL containing named parameters
  `paramSource` - container of arguments and SQL types to bind to the query
  `generatedKeyHolder` - a `KeyHolder` that will hold the generated keys
  `keyColumnNames` - names of the columns that will have keys generated for them
Returns:
  the number of rows affected
Throws:
  `org.springframework.dao.DataAccessException` - if there is any problem issuing the update
See Also:
  - `MapSqlParameterSource`
  - `GeneratedKeyHolder`
  - `DatabaseMetaData.supportsGetGeneratedKeys()`

### batchUpdate

public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs)
Description copied from interface: `NamedParameterJdbcOperations`
Execute a batch using the supplied SQL statement with the batch of supplied arguments.

Specified by:
  `batchUpdate` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL statement to execute
  `batchArgs` - the array of `SqlParameterSource` containing the batch of arguments for the query
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 `Statement.SUCCESS_NO_INFO`/`Statement.EXECUTE_FAILED`)

### batchUpdate

public int[] batchUpdate(String sql, Map<String,?>[] batchValues)
Description copied from interface: `NamedParameterJdbcOperations`
Executes a batch using the supplied SQL statement with the batch of supplied arguments.

Specified by:
  `batchUpdate` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL statement to execute
  `batchValues` - the array of Maps containing the batch of arguments for the query
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 `Statement.SUCCESS_NO_INFO`/`Statement.EXECUTE_FAILED`)

### batchUpdate

public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs, KeyHolder generatedKeyHolder)
Description copied from interface: `NamedParameterJdbcOperations`
Execute a batch using the supplied SQL statement with the batch of supplied arguments, returning generated keys.

This method requires support for generated keys in the JDBC driver.

Specified by:
  `batchUpdate` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL statement to execute
  `batchArgs` - the array of `SqlParameterSource` containing the batch of arguments for the query
  `generatedKeyHolder` - a `KeyHolder` that will hold the generated keys
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 `Statement.SUCCESS_NO_INFO`/`Statement.EXECUTE_FAILED`)
See Also:
  - `GeneratedKeyHolder`
  - `DatabaseMetaData.supportsGetGeneratedKeys()`

### batchUpdate

public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs, KeyHolder generatedKeyHolder, @Nullable String[] keyColumnNames)
Description copied from interface: `NamedParameterJdbcOperations`
Execute a batch using the supplied SQL statement with the batch of supplied arguments, returning generated keys.

This method requires support for generated keys in the JDBC driver.

Specified by:
  `batchUpdate` in interface `NamedParameterJdbcOperations`
Parameters:
  `sql` - the SQL statement to execute
  `batchArgs` - the array of `SqlParameterSource` containing the batch of arguments for the query
  `generatedKeyHolder` - a `KeyHolder` that will hold the generated keys
  `keyColumnNames` - names of the columns that will have keys generated for them
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 `Statement.SUCCESS_NO_INFO`/`Statement.EXECUTE_FAILED`)
See Also:
  - `GeneratedKeyHolder`
  - `DatabaseMetaData.supportsGetGeneratedKeys()`

### getPreparedStatementCreator

protected PreparedStatementCreator getPreparedStatementCreator(String sql, SqlParameterSource paramSource)
Build a `PreparedStatementCreator` based on the given SQL and named parameters.

Note: Directly called from all `query` variants. Delegates to the common `getPreparedStatementCreator(String, SqlParameterSource, Consumer)` method.

Parameters:
  `sql` - the SQL statement to execute
  `paramSource` - container of arguments to bind
Returns:
  the corresponding `PreparedStatementCreator`
See Also:
  - `getPreparedStatementCreator(String, SqlParameterSource, Consumer)`

### getPreparedStatementCreator

protected PreparedStatementCreator getPreparedStatementCreator(String sql, SqlParameterSource paramSource, @Nullable Consumer<PreparedStatementCreatorFactory> customizer)
Build a `PreparedStatementCreator` based on the given SQL and named parameters.

Note: Used for the `update` variant with generated key handling, and also delegated from `getPreparedStatementCreator(String, SqlParameterSource)`.

Parameters:
  `sql` - the SQL statement to execute
  `paramSource` - container of arguments to bind
  `customizer` - callback for setting further properties on the `PreparedStatementCreatorFactory` in use, applied before the actual `newPreparedStatementCreator` call
Returns:
  the corresponding `PreparedStatementCreator`
Since:
  5.0.5
See Also:
  - `getParsedSql(String)`
  - `PreparedStatementCreatorFactory(String, List)`
  - `PreparedStatementCreatorFactory.newPreparedStatementCreator(Object[])`

### getParsedSql

protected ParsedSql getParsedSql(String sql)
Obtain a parsed representation of the given SQL statement.

The default implementation uses an LRU cache with an upper limit of 256 entries.

Parameters:
  `sql` - the original SQL statement
Returns:
  a representation of the parsed SQL statement

### getPreparedStatementCreatorFactory

protected PreparedStatementCreatorFactory getPreparedStatementCreatorFactory(ParsedSql parsedSql, SqlParameterSource paramSource)
Build a `PreparedStatementCreatorFactory` based on the given SQL and named parameters.

Parameters:
  `parsedSql` - parsed representation of the given SQL statement
  `paramSource` - container of arguments to bind
Returns:
  the corresponding `PreparedStatementCreatorFactory`
Since:
  5.1.3
See Also:
  - `getPreparedStatementCreator(String, SqlParameterSource, Consumer)`
  - `getParsedSql(String)`