JdbcTemplate的源码

 

 

注意QueryStatementCallback 是一个类。

public Object query(final String sql, final ResultSetExtractor rse) throws DataAccessException {
        if (sql == null) {
            throw new InvalidDataAccessApiUsageException("SQL must not be null");
        }
        if (JdbcUtils.countParameterPlaceholders(sql, '?', "'\"") > 0) {
            throw new InvalidDataAccessApiUsageException(
                    "Cannot execute [" + sql + "] as a static query: it contains bind variables");
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Executing SQL query [" + sql + "]");
        }
        class QueryStatementCallback implements StatementCallback, SqlProvider {
            public Object doInStatement(Statement stmt) throws SQLException {
                ResultSet rs = null;
                try {
                    rs = stmt.executeQuery(sql);
                    ResultSet rsToUse = rs;
                    if (nativeJdbcExtractor != null) {
                        rsToUse = nativeJdbcExtractor.getNativeResultSet(rs);
                    }
                    return rse.extractData(rsToUse);
                }
                finally {
                    JdbcUtils.closeResultSet(rs);
                }
            }
            public String getSql() {
                return sql;
            }
        }
        return execute(new QueryStatementCallback());
    }

 

相关文章:

  • 2022-12-23
  • 2022-01-21
  • 2022-01-06
  • 2021-10-25
  • 2021-09-25
  • 2021-11-30
  • 2021-11-18
  • 2021-09-13
猜你喜欢
  • 2021-09-18
  • 2022-12-23
  • 2021-12-29
  • 2022-12-23
  • 2022-01-30
  • 2021-12-28
  • 2021-09-06
相关资源
相似解决方案