类 JdbcTemplate

  • 所有已实现的接口:
    InitializingBean, JdbcOperations

    public class JdbcTemplate
    extends JdbcAccessor
    implements JdbcOperations
    This is the central class in the JDBC core package. It simplifies the use of JDBC and helps to avoid common errors. It executes core JDBC workflow, leaving application code to provide SQL and extract results. This class executes SQL queries or updates, initiating iteration over ResultSets and catching JDBC exceptions and translating them to the generic, more informative exception hierarchy defined in the org.springframework.dao package.

    Code using this class need only implement callback interfaces, giving them a clearly defined contract. The PreparedStatementCreator callback interface creates a prepared statement given a Connection, providing SQL and any necessary parameters. The ResultSetExtractor interface extracts values from a ResultSet. See also PreparedStatementSetter and RowMapper for two popular alternative callback interfaces.

    Can be used within a service implementation via direct instantiation with a DataSource reference, or get prepared in an application context and given to services as bean reference. Note: The DataSource should always be configured as a bean in the application context, in the first case given to the service directly, in the second case to the prepared template.

    Because this class is parameterizable by the callback interfaces and the SQLExceptionTranslator interface, there should be no need to subclass it.

    All SQL operations performed by this class are logged at debug level, using "org.springframework.jdbc.core.JdbcTemplate" as log category.

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

    从以下版本开始:
    May 3, 2001
    作者:
    Rod Johnson, Juergen Hoeller, Thomas Risberg
    另请参阅:
    PreparedStatementCreator, PreparedStatementSetter, CallableStatementCreator, PreparedStatementCallback, CallableStatementCallback, ResultSetExtractor, RowCallbackHandler, RowMapper, SQLExceptionTranslator
    • 构造器详细资料

      • JdbcTemplate

        public JdbcTemplate​(DataSource dataSource)
        Construct a new JdbcTemplate, given a DataSource to obtain connections from.

        Note: This will not trigger initialization of the exception translator.

        参数:
        dataSource - the JDBC DataSource to obtain connections from
      • JdbcTemplate

        public JdbcTemplate​(DataSource dataSource,
                            boolean lazyInit)
        Construct a new JdbcTemplate, given a DataSource to obtain connections from.

        Note: Depending on the "lazyInit" flag, initialization of the exception translator will be triggered.

        参数:
        dataSource - the JDBC DataSource to obtain connections from
        lazyInit - whether to lazily initialize the SQLExceptionTranslator
    • 方法详细资料

      • isIgnoreWarnings

        public boolean isIgnoreWarnings()
        Return whether or not we ignore SQLWarnings.
      • setFetchSize

        public void setFetchSize​(int fetchSize)
        Set the fetch size for this JdbcTemplate. This is important for processing large result sets: Setting this higher than the default value will increase processing speed at the cost of memory consumption; setting this lower can avoid transferring row data that will never be read by the application.

        Default is -1, indicating to use the JDBC driver's default configuration (i.e. to not pass a specific fetch size setting on to the driver).

        Note: As of 4.3, negative values other than -1 will get passed on to the driver, since e.g. MySQL supports special behavior for Integer.MIN_VALUE.

        另请参阅:
        Statement.setFetchSize(int)
      • getFetchSize

        public int getFetchSize()
        Return the fetch size specified for this JdbcTemplate.
      • setMaxRows

        public void setMaxRows​(int maxRows)
        Set the maximum number of rows for this JdbcTemplate. This is important for processing subsets of large result sets, avoiding to read and hold the entire result set in the database or in the JDBC driver if we're never interested in the entire result in the first place (for example, when performing searches that might return a large number of matches).

        Default is -1, indicating to use the JDBC driver's default configuration (i.e. to not pass a specific max rows setting on to the driver).

        Note: As of 4.3, negative values other than -1 will get passed on to the driver, in sync with setFetchSize(int)'s support for special MySQL values.

        另请参阅:
        Statement.setMaxRows(int)
      • getMaxRows

        public int getMaxRows()
        Return the maximum number of rows specified for this JdbcTemplate.
      • setQueryTimeout

        public void setQueryTimeout​(int queryTimeout)
        Set the query timeout for statements that this JdbcTemplate executes.

        Default is -1, indicating to use the JDBC driver's default (i.e. to not pass a specific query timeout setting on the driver).

        Note: Any timeout specified here will be overridden by the remaining transaction timeout when executing within a transaction that has a timeout specified at the transaction level.

        另请参阅:
        Statement.setQueryTimeout(int)
      • getQueryTimeout

        public int getQueryTimeout()
        Return the query timeout for statements that this JdbcTemplate executes.
      • setSkipResultsProcessing

        public void setSkipResultsProcessing​(boolean skipResultsProcessing)
        Set whether results processing should be skipped. Can be used to optimize callable statement processing when we know that no results are being passed back - the processing of out parameter will still take place. This can be used to avoid a bug in some older Oracle JDBC drivers like 10.1.0.2.
      • isSkipResultsProcessing

        public boolean isSkipResultsProcessing()
        Return whether results processing should be skipped.
      • setSkipUndeclaredResults

        public void setSkipUndeclaredResults​(boolean skipUndeclaredResults)
        Set whether undeclared results should be skipped.
      • isSkipUndeclaredResults

        public boolean isSkipUndeclaredResults()
        Return whether undeclared results should be skipped.
      • setResultsMapCaseInsensitive

        public void setResultsMapCaseInsensitive​(boolean resultsMapCaseInsensitive)
        Set whether execution of a CallableStatement will return the results in a Map that uses case insensitive names for the parameters.
      • isResultsMapCaseInsensitive

        public boolean isResultsMapCaseInsensitive()
        Return whether execution of a CallableStatement will return the results in a Map that uses case insensitive names for the parameters.
      • execute

        @Nullable
        public <T> T execute​(ConnectionCallback<T> action)
                      throws DataAccessException
        从接口复制的说明: JdbcOperations
        Execute a JDBC data access operation, implemented as callback action working on a JDBC Connection. This allows for implementing arbitrary data access operations, 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.

        指定者:
        execute 在接口中 JdbcOperations
        参数:
        action - a callback object that specifies the action
        返回:
        a result object returned by the action, or null if none
        抛出:
        DataAccessException - if there is any problem
      • execute

        @Nullable
        public <T> T execute​(StatementCallback<T> action)
                      throws DataAccessException
        从接口复制的说明: JdbcOperations
        Execute a JDBC data access operation, implemented as callback action working on a JDBC Statement. 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.

        指定者:
        execute 在接口中 JdbcOperations
        参数:
        action - a callback that specifies the action
        返回:
        a result object returned by the action, or null if none
        抛出:
        DataAccessException - if there is any problem
      • queryForList

        public <T> List<T> queryForList​(String sql,
                                        Class<T> elementType)
                                 throws DataAccessException
        从接口复制的说明: JdbcOperations
        Execute a query for a result list, given static SQL.

        Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded queryForList method with null as argument array.

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

        指定者:
        queryForList 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        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 there is any problem executing the query
        另请参阅:
        JdbcOperations.queryForList(String, Class, Object...), SingleColumnRowMapper
      • queryForList

        public List<Map<String,​Object>> queryForList​(String sql)
                                                    throws DataAccessException
        从接口复制的说明: JdbcOperations
        Execute a query for a result list, given static SQL.

        Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded queryForList method with null as argument array.

        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.

        指定者:
        queryForList 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        返回:
        an List that contains a Map per row
        抛出:
        DataAccessException - if there is any problem executing the query
        另请参阅:
        JdbcOperations.queryForList(String, Object...)
      • queryForRowSet

        public SqlRowSet queryForRowSet​(String sql)
                                 throws DataAccessException
        从接口复制的说明: JdbcOperations
        Execute a query for an SqlRowSet, given static SQL.

        Uses a JDBC Statement, not a PreparedStatement. If you want to execute a static query with a PreparedStatement, use the overloaded queryForRowSet method with null as argument array.

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

        指定者:
        queryForRowSet 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        返回:
        an SqlRowSet representation (possibly a wrapper around a javax.sql.rowset.CachedRowSet)
        抛出:
        DataAccessException - if there is any problem executing the query
        另请参阅:
        JdbcOperations.queryForRowSet(String, Object...), SqlRowSetResultSetExtractor, CachedRowSet
      • batchUpdate

        public int[] batchUpdate​(String... sql)
                          throws DataAccessException
        从接口复制的说明: JdbcOperations
        Issue multiple SQL updates on a single JDBC Statement using batching.

        Will fall back to separate updates on a single Statement if the JDBC driver does not support batch updates.

        指定者:
        batchUpdate 在接口中 JdbcOperations
        参数:
        sql - defining an array of SQL statements that will be executed.
        返回:
        an array of the number of rows affected by each statement
        抛出:
        DataAccessException - if there is any problem executing the batch
      • execute

        @Nullable
        public <T> T execute​(PreparedStatementCreator psc,
                             PreparedStatementCallback<T> action)
                      throws DataAccessException
        从接口复制的说明: JdbcOperations
        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.

        指定者:
        execute 在接口中 JdbcOperations
        参数:
        psc - a callback that creates a PreparedStatement given a Connection
        action - a callback that specifies the action
        返回:
        a result object returned by the action, or null if none
        抛出:
        DataAccessException - if there is any problem
      • execute

        @Nullable
        public <T> T execute​(String sql,
                             PreparedStatementCallback<T> action)
                      throws DataAccessException
        从接口复制的说明: JdbcOperations
        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.

        指定者:
        execute 在接口中 JdbcOperations
        参数:
        sql - the SQL to execute
        action - a callback that specifies the action
        返回:
        a result object returned by the action, or null if none
        抛出:
        DataAccessException - if there is any problem
      • query

        @Nullable
        public <T> T query​(PreparedStatementCreator psc,
                           @Nullable
                           PreparedStatementSetter pss,
                           ResultSetExtractor<T> rse)
                    throws DataAccessException
        Query using a prepared statement, allowing for a PreparedStatementCreator and a PreparedStatementSetter. Most other query methods use this method, but application code will always work with either a creator or a setter.
        参数:
        psc - a callback that creates a PreparedStatement given a Connection
        pss - a callback that knows how to set values on the prepared statement. If this is null, the SQL will be assumed to contain no bind parameters.
        rse - a callback that will extract results
        返回:
        an arbitrary result object, as returned by the ResultSetExtractor
        抛出:
        DataAccessException - if there is any problem
      • query

        @Nullable
        public <T> T query​(String sql,
                           @Nullable
                           PreparedStatementSetter pss,
                           ResultSetExtractor<T> rse)
                    throws DataAccessException
        从接口复制的说明: JdbcOperations
        Query using a prepared statement, reading the ResultSet with a ResultSetExtractor.
        指定者:
        query 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        pss - a callback that knows how to set values on the prepared statement. If this is null, the SQL will be assumed to contain no bind parameters. Even if there are no bind parameters, this callback may be used to set the fetch size and other performance options.
        rse - a callback that will extract results
        返回:
        an arbitrary result object, as returned by the ResultSetExtractor
        抛出:
        DataAccessException - if there is any problem
      • query

        @Nullable
        public <T> T query​(String sql,
                           Object[] args,
                           int[] argTypes,
                           ResultSetExtractor<T> rse)
                    throws DataAccessException
        从接口复制的说明: JdbcOperations
        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.
        指定者:
        query 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        args - arguments to bind to the query
        argTypes - the SQL types of the arguments (constants from java.sql.Types)
        rse - a callback that will extract results
        返回:
        an arbitrary result object, as returned by the ResultSetExtractor
        抛出:
        DataAccessException - if the query fails
        另请参阅:
        Types
      • query

        @Nullable
        public <T> T query​(String sql,
                           @Nullable
                           Object[] args,
                           ResultSetExtractor<T> rse)
                    throws DataAccessException
        从接口复制的说明: JdbcOperations
        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.
        指定者:
        query 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
        rse - a callback that will extract results
        返回:
        an arbitrary result object, as returned by the ResultSetExtractor
        抛出:
        DataAccessException - if the query fails
      • query

        @Nullable
        public <T> T query​(String sql,
                           ResultSetExtractor<T> rse,
                           @Nullable
                           Object... args)
                    throws DataAccessException
        从接口复制的说明: JdbcOperations
        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.
        指定者:
        query 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        rse - a callback that will extract results
        args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
        返回:
        an arbitrary result object, as returned by the ResultSetExtractor
        抛出:
        DataAccessException - if the query fails
      • query

        public void query​(String sql,
                          @Nullable
                          PreparedStatementSetter pss,
                          RowCallbackHandler rch)
                   throws DataAccessException
        从接口复制的说明: JdbcOperations
        Query given SQL to create a prepared statement from SQL and a PreparedStatementSetter implementation that knows how to bind values to the query, reading the ResultSet on a per-row basis with a RowCallbackHandler.
        指定者:
        query 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        pss - a callback that knows how to set values on the prepared statement. If this is null, the SQL will be assumed to contain no bind parameters. Even if there are no bind parameters, this callback may be used to set the fetch size and other performance options.
        rch - a callback that will extract results, one row at a time
        抛出:
        DataAccessException - if the query fails
      • query

        public void query​(String sql,
                          Object[] args,
                          int[] argTypes,
                          RowCallbackHandler rch)
                   throws DataAccessException
        从接口复制的说明: JdbcOperations
        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.
        指定者:
        query 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        args - arguments to bind to the query
        argTypes - the SQL types of the arguments (constants from java.sql.Types)
        rch - a callback that will extract results, one row at a time
        抛出:
        DataAccessException - if the query fails
        另请参阅:
        Types
      • query

        public void query​(String sql,
                          @Nullable
                          Object[] args,
                          RowCallbackHandler rch)
                   throws DataAccessException
        从接口复制的说明: JdbcOperations
        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.
        指定者:
        query 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
        rch - a callback that will extract results, one row at a time
        抛出:
        DataAccessException - if the query fails
      • query

        public void query​(String sql,
                          RowCallbackHandler rch,
                          @Nullable
                          Object... args)
                   throws DataAccessException
        从接口复制的说明: JdbcOperations
        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.
        指定者:
        query 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        rch - a callback that will extract results, one row at a time
        args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
        抛出:
        DataAccessException - if the query fails
      • query

        public <T> List<T> query​(String sql,
                                 @Nullable
                                 PreparedStatementSetter pss,
                                 RowMapper<T> rowMapper)
                          throws DataAccessException
        从接口复制的说明: JdbcOperations
        Query given SQL to create a prepared statement from SQL and a PreparedStatementSetter implementation that knows how to bind values to the query, mapping each row to a result object via a RowMapper.
        指定者:
        query 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        pss - a callback that knows how to set values on the prepared statement. If this is null, the SQL will be assumed to contain no bind parameters. Even if there are no bind parameters, this callback may be used to set the fetch size and other performance options.
        rowMapper - a callback that will map one object per row
        返回:
        the result List, containing mapped objects
        抛出:
        DataAccessException - if the query fails
      • query

        public <T> List<T> query​(String sql,
                                 Object[] args,
                                 int[] argTypes,
                                 RowMapper<T> rowMapper)
                          throws DataAccessException
        从接口复制的说明: JdbcOperations
        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 result object via a RowMapper.
        指定者:
        query 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        args - arguments to bind to the query
        argTypes - the SQL types of the arguments (constants from java.sql.Types)
        rowMapper - a callback that will map one object per row
        返回:
        the result List, containing mapped objects
        抛出:
        DataAccessException - if the query fails
        另请参阅:
        Types
      • query

        public <T> List<T> query​(String sql,
                                 @Nullable
                                 Object[] args,
                                 RowMapper<T> rowMapper)
                          throws DataAccessException
        从接口复制的说明: JdbcOperations
        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 result object via a RowMapper.
        指定者:
        query 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
        rowMapper - a callback that will map one object per row
        返回:
        the result List, containing mapped objects
        抛出:
        DataAccessException - if the query fails
      • query

        public <T> List<T> query​(String sql,
                                 RowMapper<T> rowMapper,
                                 @Nullable
                                 Object... args)
                          throws DataAccessException
        从接口复制的说明: JdbcOperations
        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 result object via a RowMapper.
        指定者:
        query 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        rowMapper - a callback that will map one object per row
        args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
        返回:
        the result List, containing mapped objects
        抛出:
        DataAccessException - if the query fails
      • queryForObject

        @Nullable
        public <T> T queryForObject​(String sql,
                                    Object[] args,
                                    int[] argTypes,
                                    RowMapper<T> rowMapper)
                             throws DataAccessException
        从接口复制的说明: JdbcOperations
        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 result object via a RowMapper.
        指定者:
        queryForObject 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type)
        argTypes - the SQL types of the arguments (constants from java.sql.Types)
        rowMapper - a callback 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
        DataAccessException - if the query fails
      • queryForObject

        @Nullable
        public <T> T queryForObject​(String sql,
                                    Object[] args,
                                    int[] argTypes,
                                    Class<T> requiredType)
                             throws DataAccessException
        从接口复制的说明: JdbcOperations
        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.

        指定者:
        queryForObject 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        args - arguments to bind to the query
        argTypes - the SQL types of the arguments (constants from java.sql.Types)
        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
        另请参阅:
        JdbcOperations.queryForObject(String, Class), Types
      • queryForObject

        public <T> T queryForObject​(String sql,
                                    @Nullable
                                    Object[] args,
                                    Class<T> requiredType)
                             throws DataAccessException
        从接口复制的说明: JdbcOperations
        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.

        指定者:
        queryForObject 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
        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
        另请参阅:
        JdbcOperations.queryForObject(String, Class)
      • queryForObject

        public <T> T queryForObject​(String sql,
                                    Class<T> requiredType,
                                    @Nullable
                                    Object... args)
                             throws DataAccessException
        从接口复制的说明: JdbcOperations
        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.

        指定者:
        queryForObject 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        requiredType - the type that the result object is expected to match
        args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
        返回:
        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
        另请参阅:
        JdbcOperations.queryForObject(String, Class)
      • queryForMap

        public Map<String,​ObjectqueryForMap​(String sql,
                                                    @Nullable
                                                    Object... args)
                                             throws DataAccessException
        从接口复制的说明: JdbcOperations
        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).

        指定者:
        queryForMap 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
        返回:
        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
        另请参阅:
        JdbcOperations.queryForMap(String), ColumnMapRowMapper
      • queryForList

        public <T> List<T> queryForList​(String sql,
                                        Object[] args,
                                        int[] argTypes,
                                        Class<T> elementType)
                                 throws DataAccessException
        从接口复制的说明: JdbcOperations
        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.

        指定者:
        queryForList 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        args - arguments to bind to the query
        argTypes - the SQL types of the arguments (constants from java.sql.Types)
        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
        另请参阅:
        JdbcOperations.queryForList(String, Class), SingleColumnRowMapper
      • queryForList

        public <T> List<T> queryForList​(String sql,
                                        @Nullable
                                        Object[] args,
                                        Class<T> elementType)
                                 throws DataAccessException
        从接口复制的说明: JdbcOperations
        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.

        指定者:
        queryForList 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
        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
        另请参阅:
        JdbcOperations.queryForList(String, Class), SingleColumnRowMapper
      • queryForList

        public <T> List<T> queryForList​(String sql,
                                        Class<T> elementType,
                                        @Nullable
                                        Object... args)
                                 throws DataAccessException
        从接口复制的说明: JdbcOperations
        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.

        指定者:
        queryForList 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        elementType - the required type of element in the result list (for example, Integer.class)
        args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
        返回:
        a List of objects that match the specified element type
        抛出:
        DataAccessException - if the query fails
        另请参阅:
        JdbcOperations.queryForList(String, Class), SingleColumnRowMapper
      • queryForList

        public List<Map<String,​Object>> queryForList​(String sql,
                                                           Object[] args,
                                                           int[] argTypes)
                                                    throws DataAccessException
        从接口复制的说明: JdbcOperations
        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.

        指定者:
        queryForList 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        args - arguments to bind to the query
        argTypes - the SQL types of the arguments (constants from java.sql.Types)
        返回:
        a List that contains a Map per row
        抛出:
        DataAccessException - if the query fails
        另请参阅:
        JdbcOperations.queryForList(String), Types
      • queryForList

        public List<Map<String,​Object>> queryForList​(String sql,
                                                           @Nullable
                                                           Object... args)
                                                    throws DataAccessException
        从接口复制的说明: JdbcOperations
        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.

        指定者:
        queryForList 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
        返回:
        a List that contains a Map per row
        抛出:
        DataAccessException - if the query fails
        另请参阅:
        JdbcOperations.queryForList(String)
      • queryForRowSet

        public SqlRowSet queryForRowSet​(String sql,
                                        Object[] args,
                                        int[] argTypes)
                                 throws DataAccessException
        从接口复制的说明: JdbcOperations
        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, 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).

        指定者:
        queryForRowSet 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        args - arguments to bind to the query
        argTypes - the SQL types of the arguments (constants from java.sql.Types)
        返回:
        an SqlRowSet representation (possibly a wrapper around a javax.sql.rowset.CachedRowSet)
        抛出:
        DataAccessException - if there is any problem executing the query
        另请参阅:
        JdbcOperations.queryForRowSet(String), SqlRowSetResultSetExtractor, CachedRowSet, Types
      • queryForRowSet

        public SqlRowSet queryForRowSet​(String sql,
                                        @Nullable
                                        Object... args)
                                 throws DataAccessException
        从接口复制的说明: JdbcOperations
        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, 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).

        指定者:
        queryForRowSet 在接口中 JdbcOperations
        参数:
        sql - the SQL query to execute
        args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
        返回:
        an SqlRowSet representation (possibly a wrapper around a javax.sql.rowset.CachedRowSet)
        抛出:
        DataAccessException - if there is any problem executing the query
        另请参阅:
        JdbcOperations.queryForRowSet(String), SqlRowSetResultSetExtractor, CachedRowSet
      • update

        public int update​(PreparedStatementCreator psc)
                   throws DataAccessException
        从接口复制的说明: JdbcOperations
        Issue a single SQL update operation (such as an insert, update or delete statement) using a PreparedStatementCreator to provide SQL and any required parameters.

        A PreparedStatementCreator can either be implemented directly or configured through a PreparedStatementCreatorFactory.

        指定者:
        update 在接口中 JdbcOperations
        参数:
        psc - a callback that provides SQL and any necessary parameters
        返回:
        the number of rows affected
        抛出:
        DataAccessException - if there is any problem issuing the update
        另请参阅:
        PreparedStatementCreatorFactory
      • update

        public int update​(PreparedStatementCreator psc,
                          KeyHolder generatedKeyHolder)
                   throws DataAccessException
        从接口复制的说明: JdbcOperations
        Issue an update statement using a PreparedStatementCreator to provide SQL and any required parameters. Generated keys will be put into the given KeyHolder.

        Note that the given PreparedStatementCreator has to create a statement with activated extraction of generated keys (a JDBC 3.0 feature). This can either be done directly or through using a PreparedStatementCreatorFactory.

        指定者:
        update 在接口中 JdbcOperations
        参数:
        psc - a callback that provides SQL and any necessary parameters
        generatedKeyHolder - a KeyHolder that will hold the generated keys
        返回:
        the number of rows affected
        抛出:
        DataAccessException - if there is any problem issuing the update
        另请参阅:
        PreparedStatementCreatorFactory, GeneratedKeyHolder
      • update

        public int update​(String sql,
                          @Nullable
                          PreparedStatementSetter pss)
                   throws DataAccessException
        从接口复制的说明: JdbcOperations
        Issue an update statement using a PreparedStatementSetter to set bind parameters, with given SQL. Simpler than using a PreparedStatementCreator as this method will create the PreparedStatement: The PreparedStatementSetter just needs to set parameters.
        指定者:
        update 在接口中 JdbcOperations
        参数:
        sql - the SQL containing bind parameters
        pss - helper that sets bind parameters. If this is null we run an update with static SQL.
        返回:
        the number of rows affected
        抛出:
        DataAccessException - if there is any problem issuing the update
      • update

        public int update​(String sql,
                          Object[] args,
                          int[] argTypes)
                   throws DataAccessException
        从接口复制的说明: JdbcOperations
        Issue a single SQL update operation (such as an insert, update or delete statement) via a prepared statement, binding the given arguments.
        指定者:
        update 在接口中 JdbcOperations
        参数:
        sql - the SQL containing bind parameters
        args - arguments to bind to the query
        argTypes - the SQL types of the arguments (constants from java.sql.Types)
        返回:
        the number of rows affected
        抛出:
        DataAccessException - if there is any problem issuing the update
        另请参阅:
        Types
      • update

        public int update​(String sql,
                          @Nullable
                          Object... args)
                   throws DataAccessException
        从接口复制的说明: JdbcOperations
        Issue a single SQL update operation (such as an insert, update or delete statement) via a prepared statement, binding the given arguments.
        指定者:
        update 在接口中 JdbcOperations
        参数:
        sql - the SQL containing bind parameters
        args - arguments to bind to the query (leaving it to the PreparedStatement to guess the corresponding SQL type); may also contain SqlParameterValue objects which indicate not only the argument value but also the SQL type and optionally the scale
        返回:
        the number of rows affected
        抛出:
        DataAccessException - if there is any problem issuing the update
      • batchUpdate

        public int[] batchUpdate​(String sql,
                                 BatchPreparedStatementSetter pss)
                          throws DataAccessException
        从接口复制的说明: JdbcOperations
        Issue multiple update statements on a single PreparedStatement, using batch updates and a BatchPreparedStatementSetter to set values.

        Will fall back to separate updates on a single PreparedStatement if the JDBC driver does not support batch updates.

        指定者:
        batchUpdate 在接口中 JdbcOperations
        参数:
        sql - defining PreparedStatement that will be reused. All statements in the batch will use the same SQL.
        pss - object to set parameters on the PreparedStatement created by this method
        返回:
        an array of the number of rows affected by each statement (may also contain special JDBC-defined negative values for affected rows such as Statement.SUCCESS_NO_INFO/Statement.EXECUTE_FAILED)
        抛出:
        DataAccessException - if there is any problem issuing the update
      • batchUpdate

        public int[] batchUpdate​(String sql,
                                 List<Object[]> batchArgs,
                                 int[] argTypes)
                          throws DataAccessException
        从接口复制的说明: JdbcOperations
        Execute a batch using the supplied SQL statement with the batch of supplied arguments.
        指定者:
        batchUpdate 在接口中 JdbcOperations
        参数:
        sql - the SQL statement to execute.
        batchArgs - the List of Object arrays containing the batch of arguments for the query
        argTypes - the SQL types of the arguments (constants from java.sql.Types)
        返回:
        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)
        抛出:
        DataAccessException - if there is any problem issuing the update
      • batchUpdate

        public <T> int[][] batchUpdate​(String sql,
                                       Collection<T> batchArgs,
                                       int batchSize,
                                       ParameterizedPreparedStatementSetter<T> pss)
                                throws DataAccessException
        从接口复制的说明: JdbcOperations
        Execute multiple batches using the supplied SQL statement with the collect of supplied arguments. The arguments' values will be set using the ParameterizedPreparedStatementSetter. Each batch should be of size indicated in 'batchSize'.
        指定者:
        batchUpdate 在接口中 JdbcOperations
        参数:
        sql - the SQL statement to execute.
        batchArgs - the List of Object arrays containing the batch of arguments for the query
        batchSize - batch size
        pss - the ParameterizedPreparedStatementSetter to use
        返回:
        an array containing for each batch another 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)
        抛出:
        DataAccessException - if there is any problem issuing the update
      • execute

        @Nullable
        public <T> T execute​(CallableStatementCreator csc,
                             CallableStatementCallback<T> action)
                      throws DataAccessException
        从接口复制的说明: JdbcOperations
        Execute a JDBC data access operation, implemented as callback action working on a JDBC CallableStatement. 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.

        指定者:
        execute 在接口中 JdbcOperations
        参数:
        csc - a callback that creates a CallableStatement given a Connection
        action - a callback that specifies the action
        返回:
        a result object returned by the action, or null if none
        抛出:
        DataAccessException - if there is any problem
      • execute

        @Nullable
        public <T> T execute​(String callString,
                             CallableStatementCallback<T> action)
                      throws DataAccessException
        从接口复制的说明: JdbcOperations
        Execute a JDBC data access operation, implemented as callback action working on a JDBC CallableStatement. 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.

        指定者:
        execute 在接口中 JdbcOperations
        参数:
        callString - the SQL call string to execute
        action - a callback that specifies the action
        返回:
        a result object returned by the action, or null if none
        抛出:
        DataAccessException - if there is any problem
      • getSingleColumnRowMapper

        protected <T> RowMapper<T> getSingleColumnRowMapper​(Class<T> requiredType)
        Create a new RowMapper for reading result objects from a single column.
        参数:
        requiredType - the type that each result object is expected to match
        返回:
        the RowMapper to use
        另请参阅:
        SingleColumnRowMapper
      • newArgTypePreparedStatementSetter

        protected PreparedStatementSetter newArgTypePreparedStatementSetter​(Object[] args,
                                                                            int[] argTypes)
        Create a new arg-type-based PreparedStatementSetter using the args and types passed in.

        By default, we'll create an ArgumentTypePreparedStatementSetter. This method allows for the creation to be overridden by subclasses.

        参数:
        args - object array with arguments
        argTypes - int array of SQLTypes for the associated arguments
        返回:
        the new PreparedStatementSetter to use
      • handleWarnings

        protected void handleWarnings​(@Nullable
                                      SQLWarning warning)
                               throws SQLWarningException
        Throw an SQLWarningException if encountering an actual warning.
        参数:
        warning - the warnings object from the current statement. May be null, in which case this method does nothing.
        抛出:
        SQLWarningException - in case of an actual warning to be raised