根据查询条件获取结果集列表

@param sql
@param params 无参数时可以为null

@return
541866
public List<ENTITY> findBySQL(String sql, List<?> params) {
        RowMapper<ENTITY> mapper = new GenericMapper<ENTITY, KEY>(orMapping);
        return findBySQL(sql, params, mapper);
    }
353502
public static <T> List<T> queryForList(String sql, Class<T> clz, Object... args) {
		List<T> result = new ArrayList<T>();
		Connection con = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			con = getconnnection();
			ps = con.prepareStatement(sql);
			if (args != null) {
				for (int i = 0; i < args.length; i++) {
					ps.setObject((i + 1), args[i]);
				}
			}
			rs = ps.executeQuery();
			ResultSetMetaData rsmd = rs.getMetaData();
			int columnCount = rsmd.getColumnCount();
			while (rs.next()) {
				T obj = clz.newInstance();
				for (int i = 1; i <= columnCount; i++) {
					String columnName = rsmd.getColumnName(i);
					String methodName = "set" + columnName.substring(0, 1).toUpperCase()
							+ columnName.substring(1, columnName.length());
					Method method[] = clz.getMethods();
					for (Method meth : method) {
						if (methodName.equals(meth.getName())) {
							meth.invoke(obj, rs.getObject(i));
						}
					}
				}
				result.add(obj);
			}
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} finally {
			close(rs, ps, con);
		}
		return result;
	}
527897
public <S> List<S> queryList(Class<S> type, String sql, List<Object> params) {
        return this.queryList(type, sql, params.toArray());
    }
1263089
public <E extends Object> int executeSQL(String sql, List<E> params) {
        if (params == null || params.size() == 0) {
            return jdbcTemplate.update(sql);
        } else {
            return jdbcTemplate.update(sql, params.toArray(new Object[params.size()]));
        }
    }
781716
@Override
	public SqlContext paramMap(final Map<String, ?> paramMap) {
		if (paramMap != null) {
			paramMap.forEach((k, v) -> param(k, v));
		}
		return this;
	}
175279
public function parseSqlNameParamsToQuestionMark($sql, &$params)
    {
        $params = [];
        $hash = Random::letter(16, 16);
        $items = [];
        $index = 0;
        // 先替换字符串
        $sql = preg_replace_callback('/\'([^\']+)\'/', function($matches) use($hash, &$items, &$index){
            $items[] = $matches[0];
            $returnValue = $hash . '-' . $index;
            ++$index;
            return $returnValue;
        }, $sql);

        // 匹配 :xxx 参数
        $i = 0;
        $sql = preg_replace_callback('/(\?|:\w+)/', function($matches) use(&$params, &$i){
            if('?' === $matches[1])
            {
                $params[] = $i;
            }
            else
            {
                $params[] = $matches[1];
            }
            ++$i;
            return '?';
        }, $sql);

        // 把开始的替换回来
        for($index -= 1; $index >= 0; --$index)
        {
            $sql = str_replace($hash .'-' . $index, $items[$index], $sql);
        }

        return $sql;
    }
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);
		}
	}
5818
public static Set<String> getSqlParams(final String sql) {
		SqlParser parser = new SqlParserImpl(sql);
		ContextTransformer transformer = parser.parse();
		Node rootNode = transformer.getRoot();

		Set<String> params = new LinkedHashSet<>();
		traverseNode(rootNode, params);
		params.removeIf(s -> CONSTANT_PAT.matcher(s).matches());
		return params;
	}
810069
public function query($sql=null, array $params=[]) {
		if($sql === null) {
			$sql = $this->buildSQL();
			$params = $this->getParameters();
		}

		$this->replaceArrayParams($sql, $params);

		return $this->query = $this->db->query($sql, $params);
	}
1258733
public <T extends Object, O extends Object> List<T> findBySQL(String sql, List<O> params, RowMapper<T> mapper) {

        if (sql == null) {
            recordLog(" param sql is null!");
        }

        // 构造参数
        Object[] args = null;
        if (params == null) {
            args = new Object[0];
        } else {
            args = params.toArray(new Object[params.size()]);
        }

        // 查询
        if (params != null) {
            recordLog(sql + "\t" + params.toString());
        } else {
            recordLog(sql);
        }
        return (List<T>) jdbcTemplate.query(sql, args, mapper);
    }
1094228
private void get(final StringBuilder sql) {
        sql.append("SELECT * FROM ").append(getName()).append(" WHERE ").append(JdbcRepositories.getDefaultKeyName()).append(" = ?");
    }
319460
public List<Map<String, Object>> queryListMap(String sql, Object[] params) {
        Connection conn = getConn();
        try {
            return conn.createQuery(sql)
                    .withParams(params)
                    .setAutoDeriveColumnNames(true)
                    .throwOnMappingFailure(false)
                    .executeAndFetchTable()
                    .asList();
        } finally {
            this.closeConn(conn);
            this.clean(null);
        }
    }
172274
public int count(String sql, Object[] params) {
				
		int rowCount = 0;
		try{
			Map<String, Object> resultMap = null;
			if (params == null || params.length == 0) {
				resultMap = getProxy().queryForMap(sql);
			} else {
				resultMap = getProxy().queryForMap(sql, params);
			}
			Iterator<Map.Entry<String, Object>> it = resultMap.entrySet().iterator();
			if(it.hasNext()){
				Map.Entry<String, Object> entry = it.next();
				rowCount = ((Long)entry.getValue()).intValue();
			}
		}catch(EmptyResultDataAccessException e){
			
		}
		
		
		return rowCount;
	}
786722
public function sql(string $sql, array $params = []) {
        return $this->loadWiths($this->modelManager->sql($sql, $params));
    }
681601
public static String getSQL(String sql, StatementParameter param) {
		int i = 0;
		while (sql.indexOf('?') > -1) {
			if (param == null) {
				throw new InvalidParamDataAccessException("没有设置参数.");
			}
			if (i >= param.size()) {
				return sql;
			}
			Class<?> type = param.getType(i);
			Object obj = param.getObject(i);
			String value = getValue(type, obj);
			sql = sql.substring(0, sql.indexOf('?')) + value + sql.substring(sql.indexOf('?') + 1, sql.length());
			i++;
		}
		return sql;//
	}
274011
public String queryString(String sql, Object... params) throws SQLException {
		return query(sql, new StringHandler(), params);
	}
886618
public void createPreparedStatement(String query, List<Object> params) throws SQLException {

        m_preparedStatement = m_connection.prepareStatement(query);

        // Check the params
        if (params != null) {
            for (int i = 0; i < params.size(); i++) {
                Object item = params.get(i);

                // Check if the parameter is a string
                if (item instanceof String) {
                    m_preparedStatement.setString(i + 1, (String)item);
                }
                if (item instanceof Integer) {
                    Integer number = (Integer)item;
                    m_preparedStatement.setInt(i + 1, number.intValue());
                }
                if (item instanceof Long) {
                    Long longNumber = (Long)item;
                    m_preparedStatement.setLong(i + 1, longNumber.longValue());
                }

                // If item is none of types above set the statement to use the bytes
                if (!(item instanceof Integer) && !(item instanceof String) && !(item instanceof Long)) {
                    try {
                        m_preparedStatement.setBytes(i + 1, CmsDataTypeUtil.dataSerialize(item));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }

    }