接口 NamedParameterJdbcOperations

    • 方法概要

      所有方法 实例方法 抽象方法 
      修饰符和类型方法说明
      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.
      <T> Texecute​(String sql, Map<String,​?> paramMap, PreparedStatementCallback<T> action)
      Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement.
      <T> Texecute​(String sql, SqlParameterSource paramSource, PreparedStatementCallback<T> action)
      Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement.
      <T> Texecute​(String sql, PreparedStatementCallback<T> action)
      Execute a JDBC data access operation, implemented as callback action working on a JDBC PreparedStatement.
      JdbcOperationsgetJdbcOperations()
      Expose the classic Spring JdbcTemplate to allow invocation of classic JDBC operations.
      <T> Tquery​(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.
      voidquery​(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> Tquery​(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.
      voidquery​(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> Tquery​(String sql, ResultSetExtractor<T> rse)
      Query given SQL to create a prepared statement from SQL, reading the ResultSet with a ResultSetExtractor.
      voidquery​(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> TqueryForObject​(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> TqueryForObject​(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> TqueryForObject​(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> TqueryForObject​(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.
      SqlRowSetqueryForRowSet​(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 SqlRowSet.
      SqlRowSetqueryForRowSet​(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.
      intupdate​(String sql, Map<String,​?> paramMap)
      Issue an update via a prepared statement, binding the given arguments.
      intupdate​(String sql, SqlParameterSource paramSource)
      Issue an update via a prepared statement, binding the given arguments.
      intupdate​(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder)
      Issue an update via a prepared statement, binding the given arguments, returning generated keys.
      intupdate​(String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder, String[] keyColumnNames)
      Issue an update via a prepared statement, binding the given arguments, returning generated keys.
    • 方法详细资料

      • execute

        <T> T execute​(String sql,
                      SqlParameterSource paramSource,
                      PreparedStatementCallback<T> action)
               throws DataAccessException
        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.

        参数:
        sql - the SQL to execute
        paramSource - container of arguments to bind to the query
        action - callback object that specifies the action
        返回:
        a result object returned by the action, or null
        抛出:
        DataAccessException - if there is any problem
      • execute

        <T> T execute​(String sql,
                      Map<String,​?> paramMap,
                      PreparedStatementCallback<T> action)
               throws DataAccessException
        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.

        参数:
        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
        返回:
        a result object returned by the action, or null
        抛出:
        DataAccessException - if there is any problem
      • execute

        <T> T execute​(String sql,
                      PreparedStatementCallback<T> action)
               throws DataAccessException
        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.

        参数:
        sql - the SQL to execute
        action - callback object that specifies the action
        返回:
        a result object returned by the action, or null
        抛出:
        DataAccessException - if there is any problem
      • query

        <T> T query​(String sql,
                    SqlParameterSource paramSource,
                    ResultSetExtractor<T> rse)
             throws DataAccessException
        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.
        参数:
        sql - the SQL query to execute
        paramSource - container of arguments to bind to the query
        rse - object that will extract results
        返回:
        an arbitrary result object, as returned by the ResultSetExtractor
        抛出:
        DataAccessException - if the query fails
      • query

        <T> T query​(String sql,
                    Map<String,​?> paramMap,
                    ResultSetExtractor<T> rse)
             throws DataAccessException
        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.
        参数:
        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
        返回:
        an arbitrary result object, as returned by the ResultSetExtractor
        抛出:
        DataAccessException - if the query fails
      • query

        <T> T query​(String sql,
                    ResultSetExtractor<T> rse)
             throws DataAccessException
        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.

        参数:
        sql - the SQL query to execute
        rse - object that will extract results
        返回:
        an arbitrary result object, as returned by the ResultSetExtractor
        抛出:
        DataAccessException - if the query fails
      • query

        void query​(String sql,
                   SqlParameterSource paramSource,
                   RowCallbackHandler rch)
            throws DataAccessException
        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.
        参数:
        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
        抛出:
        DataAccessException - if the query fails
      • query

        void query​(String sql,
                   Map<String,​?> paramMap,
                   RowCallbackHandler rch)
            throws DataAccessException
        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.
        参数:
        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
        抛出:
        DataAccessException - if the query fails
      • query

        void query​(String sql,
                   RowCallbackHandler rch)
            throws DataAccessException
        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.

        参数:
        sql - the SQL query to execute
        rch - object that will extract results, one row at a time
        抛出:
        DataAccessException - if the query fails
      • query

        <T> List<T> query​(String sql,
                          SqlParameterSource paramSource,
                          RowMapper<T> rowMapper)
                   throws DataAccessException
        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.
        参数:
        sql - the SQL query to execute
        paramSource - container of arguments to bind to the query
        rowMapper - object that will map one object per row
        返回:
        the result List, containing mapped objects
        抛出:
        DataAccessException - if the query fails
      • query

        <T> List<T> query​(String sql,
                          Map<String,​?> paramMap,
                          RowMapper<T> rowMapper)
                   throws DataAccessException
        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.
        参数:
        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
        返回:
        the result List, containing mapped objects
        抛出:
        DataAccessException - if the query fails
      • query

        <T> List<T> query​(String sql,
                          RowMapper<T> rowMapper)
                   throws DataAccessException
        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.

        参数:
        sql - the SQL query to execute
        rowMapper - object that will map one object per row
        返回:
        the result List, containing mapped objects
        抛出:
        DataAccessException - if the query fails
      • queryForObject

        <T> T queryForObject​(String sql,
                             SqlParameterSource paramSource,
                             RowMapper<T> rowMapper)
                      throws DataAccessException
        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.
        参数:
        sql - the SQL query to execute
        paramSource - container of arguments to bind to the query
        rowMapper - object that will map one object per row
        返回:
        the single mapped object (may be null if the given RowMapper returned null)
        抛出:
        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

        <T> T queryForObject​(String sql,
                             Map<String,​?> paramMap,
                             RowMapper<T> rowMapper)
                      throws DataAccessException
        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.
        参数:
        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
        返回:
        the single mapped object (may be null if the given RowMapper returned null)
        抛出:
        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

        <T> T queryForObject​(String sql,
                             SqlParameterSource paramSource,
                             Class<T> requiredType)
                      throws DataAccessException
        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.

        参数:
        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
        返回:
        the result object of the required type, or null in case of SQL NULL
        抛出:
        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
        另请参阅:
        JdbcTemplate.queryForObject(String, Class)
      • queryForObject

        <T> T queryForObject​(String sql,
                             Map<String,​?> paramMap,
                             Class<T> requiredType)
                      throws DataAccessException
        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.

        参数:
        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
        返回:
        the result object of the required type, or null in case of SQL NULL
        抛出:
        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
        另请参阅:
        JdbcTemplate.queryForObject(String, Class)
      • queryForMap

        Map<String,​ObjectqueryForMap​(String sql,
                                             Map<String,​?> paramMap)
                                      throws DataAccessException
        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).

        参数:
        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)
        返回:
        the result Map (one entry for each column, using the column name as the key)
        抛出:
        IncorrectResultSizeDataAccessException - if the query does not return exactly one row
        DataAccessException - if the query fails
        另请参阅:
        JdbcTemplate.queryForMap(String), ColumnMapRowMapper
      • queryForList

        <T> List<T> queryForList​(String sql,
                                 SqlParameterSource paramSource,
                                 Class<T> elementType)
                          throws DataAccessException
        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.

        参数:
        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)
        返回:
        a List of objects that match the specified element type
        抛出:
        DataAccessException - if the query fails
        另请参阅:
        JdbcTemplate.queryForList(String, Class), SingleColumnRowMapper
      • queryForList

        <T> List<T> queryForList​(String sql,
                                 Map<String,​?> paramMap,
                                 Class<T> elementType)
                          throws DataAccessException
        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.

        参数:
        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)
        返回:
        a List of objects that match the specified element type
        抛出:
        DataAccessException - if the query fails
        另请参阅:
        JdbcTemplate.queryForList(String, Class), SingleColumnRowMapper
      • queryForList

        List<Map<String,​Object>> queryForList​(String sql,
                                                    SqlParameterSource paramSource)
                                             throws DataAccessException
        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.

        参数:
        sql - the SQL query to execute
        paramSource - container of arguments to bind to the query
        返回:
        a List that contains a Map per row
        抛出:
        DataAccessException - if the query fails
        另请参阅:
        JdbcTemplate.queryForList(String)
      • queryForList

        List<Map<String,​Object>> queryForList​(String sql,
                                                    Map<String,​?> paramMap)
                                             throws DataAccessException
        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.

        参数:
        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)
        返回:
        a List that contains a Map per row
        抛出:
        DataAccessException - if the query fails
        另请参阅:
        JdbcTemplate.queryForList(String)
      • queryForRowSet

        SqlRowSet queryForRowSet​(String sql,
                                 SqlParameterSource paramSource)
                          throws DataAccessException
        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).

        参数:
        sql - the SQL query to execute
        paramSource - container of arguments to bind to the query
        返回:
        a SqlRowSet representation (possibly a wrapper around a javax.sql.rowset.CachedRowSet)
        抛出:
        DataAccessException - if there is any problem executing the query
        另请参阅:
        JdbcTemplate.queryForRowSet(String), SqlRowSetResultSetExtractor, CachedRowSet
      • queryForRowSet

        SqlRowSet queryForRowSet​(String sql,
                                 Map<String,​?> paramMap)
                          throws DataAccessException
        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).

        参数:
        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)
        返回:
        a SqlRowSet representation (possibly a wrapper around a javax.sql.rowset.CachedRowSet)
        抛出:
        DataAccessException - if there is any problem executing the query
        另请参阅:
        JdbcTemplate.queryForRowSet(String), SqlRowSetResultSetExtractor, CachedRowSet
      • update

        int update​(String sql,
                   SqlParameterSource paramSource)
            throws DataAccessException
        Issue an update via a prepared statement, binding the given arguments.
        参数:
        sql - the SQL containing named parameters
        paramSource - container of arguments and SQL types to bind to the query
        返回:
        the number of rows affected
        抛出:
        DataAccessException - if there is any problem issuing the update
      • update

        int update​(String sql,
                   Map<String,​?> paramMap)
            throws DataAccessException
        Issue an update via a prepared statement, binding the given arguments.
        参数:
        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)
        返回:
        the number of rows affected
        抛出:
        DataAccessException - if there is any problem issuing the update
      • update

        int update​(String sql,
                   SqlParameterSource paramSource,
                   KeyHolder generatedKeyHolder,
                   String[] keyColumnNames)
            throws DataAccessException
        Issue an update via a prepared statement, binding the given arguments, returning generated keys.
        参数:
        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
        返回:
        the number of rows affected
        抛出:
        DataAccessException - if there is any problem issuing the update
        另请参阅:
        MapSqlParameterSource, GeneratedKeyHolder
      • batchUpdate

        int[] batchUpdate​(String sql,
                          Map<String,​?>[] batchValues)
        Executes a batch using the supplied SQL statement with the batch of supplied arguments.
        参数:
        sql - the SQL statement to execute
        batchValues - the array of Maps containing the batch of arguments for the query
        返回:
        an array containing the numbers of rows affected by each update in the batch
        抛出:
        DataAccessException - if there is any problem issuing the update
      • batchUpdate

        int[] batchUpdate​(String sql,
                          SqlParameterSource[] batchArgs)
        Execute a batch using the supplied SQL statement with the batch of supplied arguments.
        参数:
        sql - the SQL statement to execute
        batchArgs - the array of SqlParameterSource containing the batch of arguments for the query
        返回:
        an array containing the numbers of rows affected by each update in the batch
        抛出:
        DataAccessException - if there is any problem issuing the update