org.springframework.jdbc.core.namedparam

Class NamedParameterJdbcTemplate

  • java.lang.Object
    • org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
  • All Implemented Interfaces:
    NamedParameterJdbcOperations


    public class NamedParameterJdbcTemplate
    extends java.lang.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.

    The underlying JdbcTemplate is exposed to allow for convenient access to the traditional JdbcTemplate methods.

    NOTE: An instance of this class is thread-safe once configured.

    Since:
    2.0
    Author:
    Thomas Risberg, Juergen Hoeller
    See Also:
    NamedParameterJdbcOperations, JdbcTemplate
    • Field Summary

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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      int[] batchUpdate(java.lang.String sql, java.util.Map<java.lang.String,?>[] batchValues)
      Executes a batch using the supplied SQL statement with the batch of supplied arguments.
      int[] batchUpdate(java.lang.String sql, SqlParameterSource[] batchArgs)
      Execute a batch using the supplied SQL statement with the batch of supplied arguments.
      <T> T execute(java.lang.String sql, java.util.Map<java.lang.String,?> paramMap, PreparedStatementCallback<T> action)
      Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement.
      <T> T execute(java.lang.String sql, PreparedStatementCallback<T> action)
      Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement.
      <T> T execute(java.lang.String sql, SqlParameterSource paramSource, 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(java.lang.String sql)
      Obtain a parsed representation of the given SQL statement.
      protected PreparedStatementCreator getPreparedStatementCreator(java.lang.String sql, SqlParameterSource paramSource)
      Build a PreparedStatementCreator based on the given SQL and named parameters.
      protected PreparedStatementCreator getPreparedStatementCreator(java.lang.String sql, SqlParameterSource paramSource, java.util.function.Consumer<PreparedStatementCreatorFactory> customizer)
      Build a PreparedStatementCreator based on the given SQL and named parameters.
      <T> T query(java.lang.String sql, java.util.Map<java.lang.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(java.lang.String sql, java.util.Map<java.lang.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> java.util.List<T> query(java.lang.String sql, java.util.Map<java.lang.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(java.lang.String sql, ResultSetExtractor<T> rse)
      Query given SQL to create a prepared statement from SQL, reading the ResultSet with a ResultSetExtractor.
      void query(java.lang.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> java.util.List<T> query(java.lang.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.
      <T> T query(java.lang.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(java.lang.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> java.util.List<T> query(java.lang.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.
      java.util.List<java.util.Map<java.lang.String,java.lang.Object>> queryForList(java.lang.String sql, java.util.Map<java.lang.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> java.util.List<T> queryForList(java.lang.String sql, java.util.Map<java.lang.String,?> paramMap, java.lang.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.
      java.util.List<java.util.Map<java.lang.String,java.lang.Object>> queryForList(java.lang.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> java.util.List<T> queryForList(java.lang.String sql, SqlParameterSource paramSource, java.lang.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.
      java.util.Map<java.lang.String,java.lang.Object> queryForMap(java.lang.String sql, java.util.Map<java.lang.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.
      java.util.Map<java.lang.String,java.lang.Object> queryForMap(java.lang.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(java.lang.String sql, java.util.Map<java.lang.String,?> paramMap, java.lang.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(java.lang.String sql, java.util.Map<java.lang.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(java.lang.String sql, SqlParameterSource paramSource, java.lang.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(java.lang.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(java.lang.String sql, java.util.Map<java.lang.String,?> paramMap)
      Query given SQL to create a prepared statement from SQL and a list of arguments to bind to the query, expecting a SqlRowSet.
      SqlRowSet queryForRowSet(java.lang.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 SqlRowSet.
      void setCacheLimit(int cacheLimit)
      Specify the maximum number of entries for this template's SQL cache.
      int update(java.lang.String sql, java.util.Map<java.lang.String,?> paramMap)
      Issue an update via a prepared statement, binding the given arguments.
      int update(java.lang.String sql, SqlParameterSource paramSource)
      Issue an update via a prepared statement, binding the given arguments.
      int update(java.lang.String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder)
      Issue an update via a prepared statement, binding the given arguments, returning generated keys.
      int update(java.lang.String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder, java.lang.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 Detail

      • 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 Detail

      • NamedParameterJdbcTemplate

        public NamedParameterJdbcTemplate(javax.sql.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 Detail

      • 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.
      • getCacheLimit

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

        @Nullable
        public <T> T execute(java.lang.String sql,
                                       SqlParameterSource paramSource,
                                       PreparedStatementCallback<T> action)
                                throws 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:
        DataAccessException - if there is any problem
      • execute

        @Nullable
        public <T> T execute(java.lang.String sql,
                                       java.util.Map<java.lang.String,?> paramMap,
                                       PreparedStatementCallback<T> action)
                                throws 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:
        DataAccessException - if there is any problem
      • execute

        @Nullable
        public <T> T execute(java.lang.String sql,
                                       PreparedStatementCallback<T> action)
                                throws 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:
        DataAccessException - if there is any problem
      • query

        @Nullable
        public <T> T query(java.lang.String sql,
                                     java.util.Map<java.lang.String,?> paramMap,
                                     ResultSetExtractor<T> rse)
                              throws 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:
        DataAccessException - if the query fails
      • query

        @Nullable
        public <T> T query(java.lang.String sql,
                                     ResultSetExtractor<T> rse)
                              throws 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:
        DataAccessException - if the query fails
      • query

        public void query(java.lang.String sql,
                          java.util.Map<java.lang.String,?> paramMap,
                          RowCallbackHandler rch)
                   throws 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:
        DataAccessException - if the query fails
      • query

        public void query(java.lang.String sql,
                          RowCallbackHandler rch)
                   throws 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:
        DataAccessException - if the query fails
      • query

        public <T> java.util.List<T> query(java.lang.String sql,
                                           SqlParameterSource paramSource,
                                           RowMapper<T> rowMapper)
                                    throws 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:
        DataAccessException - if the query fails
      • query

        public <T> java.util.List<T> query(java.lang.String sql,
                                           java.util.Map<java.lang.String,?> paramMap,
                                           RowMapper<T> rowMapper)
                                    throws 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:
        DataAccessException - if the query fails
      • query

        public <T> java.util.List<T> query(java.lang.String sql,
                                           RowMapper<T> rowMapper)
                                    throws 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:
        DataAccessException - if the query fails
      • queryForObject

        @Nullable
        public <T> T queryForObject(java.lang.String sql,
                                              java.util.Map<java.lang.String,?> paramMap,
                                              RowMapper<T> rowMapper)
                                       throws 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:
        IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row
        DataAccessException - if the query fails
      • queryForObject

        @Nullable
        public <T> T queryForObject(java.lang.String sql,
                                              java.util.Map<java.lang.String,?> paramMap,
                                              java.lang.Class<T> requiredType)
                                       throws 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:
        IncorrectResultSizeDataAccessException - if the query does not return exactly one row, or does not return exactly one column in that row
        DataAccessException - if the query fails
        See Also:
        JdbcTemplate.queryForObject(String, Class)
      • queryForMap

        public java.util.Map<java.lang.String,java.lang.Object> queryForMap(java.lang.String sql,
                                                                            java.util.Map<java.lang.String,?> paramMap)
                                                                     throws 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:
        IncorrectResultSizeDataAccessException - if the query does not return exactly one row
        DataAccessException - if the query fails
        See Also:
        JdbcTemplate.queryForMap(String), ColumnMapRowMapper
      • queryForList

        public <T> java.util.List<T> queryForList(java.lang.String sql,
                                                  SqlParameterSource paramSource,
                                                  java.lang.Class<T> elementType)
                                           throws 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:
        DataAccessException - if the query fails
        See Also:
        JdbcTemplate.queryForList(String, Class), SingleColumnRowMapper
      • queryForList

        public <T> java.util.List<T> queryForList(java.lang.String sql,
                                                  java.util.Map<java.lang.String,?> paramMap,
                                                  java.lang.Class<T> elementType)
                                           throws 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:
        DataAccessException - if the query fails
        See Also:
        JdbcTemplate.queryForList(String, Class), SingleColumnRowMapper
      • queryForList

        public java.util.List<java.util.Map<java.lang.String,java.lang.Object>> queryForList(java.lang.String sql,
                                                                                             SqlParameterSource paramSource)
                                                                                      throws 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:
        DataAccessException - if the query fails
        See Also:
        JdbcTemplate.queryForList(String)
      • queryForList

        public java.util.List<java.util.Map<java.lang.String,java.lang.Object>> queryForList(java.lang.String sql,
                                                                                             java.util.Map<java.lang.String,?> paramMap)
                                                                                      throws 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:
        DataAccessException - if the query fails
        See Also:
        JdbcTemplate.queryForList(String)
      • queryForRowSet

        public SqlRowSet queryForRowSet(java.lang.String sql,
                                        SqlParameterSource paramSource)
                                 throws 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 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, Sun's com.sun.rowset.CachedRowSetImpl class is used, which is part of JDK 1.5+ and also available separately as part of Sun's JDBC RowSet Implementations download (rowset.jar).

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

        public SqlRowSet queryForRowSet(java.lang.String sql,
                                        java.util.Map<java.lang.String,?> paramMap)
                                 throws 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 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, Sun's com.sun.rowset.CachedRowSetImpl class is used, which is part of JDK 1.5+ and also available separately as part of Sun's JDBC RowSet Implementations download (rowset.jar).

        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:
        a SqlRowSet representation (possibly a wrapper around a javax.sql.rowset.CachedRowSet)
        Throws:
        DataAccessException - if there is any problem executing the query
        See Also:
        JdbcTemplate.queryForRowSet(String), SqlRowSetResultSetExtractor, CachedRowSet
      • update

        public int update(java.lang.String sql,
                          java.util.Map<java.lang.String,?> paramMap)
                   throws 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:
        DataAccessException - if there is any problem issuing the update
      • batchUpdate

        public int[] batchUpdate(java.lang.String sql,
                                 java.util.Map<java.lang.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
      • batchUpdate

        public int[] batchUpdate(java.lang.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
      • getParsedSql

        protected ParsedSql getParsedSql(java.lang.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