执行查询语句<br>
此方法不会关闭Connection

@param <T> 处理结果类型
@param conn 数据库连接对象
@param sql 查询语句，使用参数名占位符，例如:name
@param rsh 结果集处理对象
@param paramMap 参数对
@return 结果对象
@throws SQLException SQL执行异常
@since 4.0.10
559538
public static <T> T query(Connection conn, String sql, RsHandler<T> rsh, Map<String, Object> paramMap) throws SQLException {
		final NamedSql namedSql = new NamedSql(sql, paramMap);
		return query(conn, namedSql.getSql(), rsh, namedSql.getParams());
	}
1283099
public <T> T page(Connection conn, Collection<String> fields, Entity where, int pageNumber, int numPerPage, RsHandler<T> rsh) throws SQLException {
		return page(conn, fields, where, new Page(pageNumber, numPerPage), rsh);
	}
671890
public static int execute(Connection conn, String sql, Object... params) throws SQLException {
		PreparedStatement ps = null;
		try {
			ps = StatementUtil.prepareStatement(conn, sql, params);
			return ps.executeUpdate();
		} finally {
			DbUtil.close(ps);
		}
	}
39325
public void execute(String query, Object... params) throws SQLException {
        createPreparedStatement(query, 0, params).execute();
    }
436517
protected PreparedStatement executeSql(String sql,
    MapSqlParameterSource args)
  {
    // XXX: uses raw type, what are the parameters to Map in MapSqlParameterSource?
    Map<String, Object> parameters = args != null ? args.getValues()
      : new HashMap<String, Object>();

    for (Map.Entry<String, Object> placeHolderEntry : parameters.entrySet())
    {
      String key = placeHolderEntry.getKey();
      String value = placeHolderEntry.getValue().toString();
      log.debug("substitution for parameter '" + key + "' in SQL script: "
        + value);
      sql = sql.replaceAll(key, Matcher.quoteReplacement(value));
    }
    
    log.debug("Executing SQL\n{}", sql);
    
    CancelableStatements cancelableStats
      = new CancelableStatements(
        sql, statementController);

    // register the statement, so we could try to interrupt it in the gui.
    if (statementController != null)
    {
      statementController.registerStatement(cancelableStats.statement);
    }
    else
    {
      log.debug("statement controller is not initialized");
    }
    getJdbcTemplate().execute(cancelableStats, cancelableStats);
    return cancelableStats.statement;

  }
1208363
public void exec(String sql, Object []params, Result<Object> result)
  {
    QueryBuilderKraken query = QueryParserKraken.parse(this, sql);
      
    query.build(result.then((q,r)->q.exec(r, params)));
  }
252708
public Long execute(final ConnectionResource _con)
        throws SQLException
    {
        final boolean supGenKey = Context.getDbType().supportsGetGeneratedKeys();

        Long ret = null;
        if (this.newId && !supGenKey)  {
            ret = Context.getDbType().getNewId(_con, getTableName(), getIdColumn());
            this.column(getIdColumn(), ret);
        }

        final StringBuilder cmd = new StringBuilder()
            .append(Context.getDbType().getSQLPart(SQLPart.INSERT))
            .append(" ")
            .append(Context.getDbType().getSQLPart(SQLPart.INTO))
            .append(" ")
            .append(Context.getDbType().getTableQuote())
            .append(getTableName())
            .append(Context.getDbType().getTableQuote())
            .append(" ")
            .append(Context.getDbType().getSQLPart(SQLPart.PARENTHESIS_OPEN));

        final StringBuilder val = new StringBuilder();

        // append SQL values
        boolean first = true;
        for (final ColumnWithSQLValue col : getColumnWithSQLValues())  {
            if (first)  {
                first = false;
            } else  {
                cmd.append(Context.getDbType().getSQLPart(SQLPart.COMMA));
                val.append(Context.getDbType().getSQLPart(SQLPart.COMMA));
            }
            cmd.append(Context.getDbType().getColumnQuote())
                .append(col.getColumnName())
                .append(Context.getDbType().getColumnQuote());
            val.append(col.getSqlValue());
        }

        // append values
        for (final AbstractColumnWithValue<?> col : getColumnWithValues())  {
            if (first)  {
                first = false;
            } else  {
                cmd.append(Context.getDbType().getSQLPart(SQLPart.COMMA));
                val.append(Context.getDbType().getSQLPart(SQLPart.COMMA));
            }
            cmd.append(Context.getDbType().getColumnQuote())
                .append(col.getColumnName())
                .append(Context.getDbType().getColumnQuote());
            val.append('?');
        }
        cmd.append(Context.getDbType().getSQLPart(SQLPart.PARENTHESIS_CLOSE))
            .append(Context.getDbType().getSQLPart(SQLPart.VALUES))
            .append(Context.getDbType().getSQLPart(SQLPart.PARENTHESIS_OPEN))
            .append(val)
            .append(Context.getDbType().getSQLPart(SQLPart.PARENTHESIS_CLOSE));

        SQLInsert.LOG.debug("Executing SQL: {}", cmd.toString());

        final PreparedStatement stmt;
        if (this.newId && supGenKey) {
            if (Context.getDbType().supportsMultiGeneratedKeys()) {
                stmt = _con.prepareStatement(cmd.toString(), new String[]{ getIdColumn() });
            } else {
                stmt = _con.prepareStatement(cmd.toString(), Statement.RETURN_GENERATED_KEYS);
            }
        } else {
            stmt = _con.prepareStatement(cmd.toString());
        }

        int index = 1;
        for (final AbstractColumnWithValue<?> col : getColumnWithValues())  {
            if (SQLInsert.LOG.isDebugEnabled()) {
                SQLInsert.LOG.debug("    " + index + " = " + col.getValue());
            }
            col.set(index++, stmt);
        }

        try {
            final int rows = stmt.executeUpdate();
            if (rows == 0) {
                throw new SQLException("Object for SQL table '" + getTableName()
                        + "' does not exists and was not inserted.");
            }

            // if auto generated get new id
            if (this.newId && supGenKey) {
                final ResultSet resultset = stmt.getGeneratedKeys();
                if (resultset.next()) {
                    ret = resultset.getLong(1);
                }
                resultset.close();
            }
        } finally  {
            stmt.close();
        }

        if (this.newId && SQLInsert.LOG.isDebugEnabled()) {
            SQLInsert.LOG.debug("new generated id " + ret);
        }

        return ret;
    }
311198
public SQLException exceptionWithQuery(ParameterHolder[] parameters, SQLException sqlEx,
      PrepareResult serverPrepareResult) {
    if (sqlEx.getCause() instanceof SocketTimeoutException) {
      return new SQLException("Connection timed out", CONNECTION_EXCEPTION.getSqlState(), sqlEx);
    }
    if (options.dumpQueriesOnException) {
      return new SQLException(exWithQuery(sqlEx.getMessage(), serverPrepareResult, parameters),
          sqlEx.getSQLState(),
          sqlEx.getErrorCode(), sqlEx.getCause());
    }
    return sqlEx;
  }
183325
def exec_query(sql, name = 'SQL', binds = [])
      # NOTE: we allow to execute SQL as requested returning a results.
      # e.g. this allows to use SQLServer's EXEC with a result set ...
      sql = to_sql(sql, binds) if sql.respond_to?(:to_sql)

      sql = repair_special_columns(sql)
      if prepared_statements?
        log(sql, name, binds) { @connection.execute_query(sql, binds) }
      else
        log(sql, name) { @connection.execute_query(sql) }
      end
    end
263356
private String exWithQuery(String message, PrepareResult serverPrepareResult,
      ParameterHolder[] parameters) {
    if (options.dumpQueriesOnException) {
      StringBuilder sql = new StringBuilder(serverPrepareResult.getSql());
      if (serverPrepareResult.getParamCount() > 0) {
        sql.append(", parameters [");
        if (parameters.length > 0) {
          for (int i = 0; i < Math.min(parameters.length, serverPrepareResult.getParamCount());
              i++) {
            sql.append(parameters[i].toString()).append(",");
          }
          sql = new StringBuilder(sql.substring(0, sql.length() - 1));
        }
        sql.append("]");
      }

      if (options.maxQuerySizeToLog != 0 && sql.length() > options.maxQuerySizeToLog - 3) {
        return message
            + "\nQuery is: " + sql.substring(0, options.maxQuerySizeToLog - 3) + "..."
            + "\njava thread: " + Thread.currentThread().getName();
      } else {
        return message
            + "\nQuery is: " + sql
            + "\njava thread: " + Thread.currentThread().getName();
      }
    }
    return message;
  }
650434
private void execute(String sql) throws SQLException {
        Statement statement = connection.createStatement();
        try {
            statement.executeUpdate(substitute(sql));
        } finally {
            DbUtils.closeQuietly(statement);
        }
    }
570331
public static int[] executeBatch(Connection conn, String sql, Iterable<Object[]> paramsBatch) throws SQLException {
		PreparedStatement ps = null;
		try {
			ps = StatementUtil.prepareStatementForBatch(conn, sql, paramsBatch);
			return ps.executeBatch();
		} finally {
			DbUtil.close(ps);
		}
	}
432448
public static String isValidSqlWithMessage(Connection con, String sql, List<QueryParameter> parameters) {		
		try {
			QueryUtil qu = new QueryUtil(con, DialectUtil.getDialect(con));
			Map<String, QueryParameter> params = new HashMap<String, QueryParameter>();			
			for (QueryParameter qp : parameters) {
				params.put(qp.getName(), qp);
			}
			qu.getColumnNames(sql, params);
		} catch (Exception ex) {
			LOG.error(ex.getMessage(), ex);
			return ex.getMessage();
		}
		return null;
	}
881759
@Override
	public final ResultSet executeQuery(String sql) throws SQLException {
		Split s = prepare(sql);
		try {
			return new SimonResultSet(stmt.executeQuery(sql), this, prefix, s.getStopwatch().getName());
		} finally {
			finish(s);
		}
	}
687080
public int execute(String sql, List<Object> params) {
        return this.execute(sql, params.toArray());
    }
1047928
public int execute(String sql, Object... params) {
        Connection conn = getConn();
        try {
            return conn.createQuery(sql)
                    .withParams(params)
                    .executeUpdate()
                    .getResult();
        } finally {
            this.closeConn(conn);
            this.clean(conn);
        }
    }
368113
public static int[] executeBatch(Connection conn, String... sqls) throws SQLException {
		return executeBatch(conn, new ArrayIter<String>(sqls));
	}