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()); }