• 偶然发现在java方法中可以定义类


    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());
        }
  • 相关阅读:
    Python经典算法-快速幂
    HTML/CSS代码片段
    JavaScript代码片段
    全选、全不选、反选
    NodeJS入门
    Ajax入门
    伪协议触发onbeforeunload
    CSS优先级、引入方式、Hack
    iframe的操作
    四:JAVA 消息队列(blockingqueue)的应用
  • 原文地址:https://www.cnblogs.com/mkl34367803/p/14728947.html
Copyright © 2020-2023  润新知