Paging query results by sql

@param sql     sql statement
@param pageRow page param
@return Page
497716
public Page<T> page(String sql, PageRow pageRow) {
        return this.page(sql, paramValues, pageRow);
    }
1305392
public List queryMultiObject(Collection queryParams, String sqlquery) throws Exception {
		Debug.logVerbose("[JdonFramework]--> enter queryMultiObject ", module);
		Connection c = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		List list = new ArrayList();
		try {
			c = dataSource.getConnection();
			ps = c.prepareStatement(sqlquery, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
			Debug.logVerbose("[JdonFramework]" + sqlquery, module);
			jdbcUtil.setQueryParams(queryParams, ps);

			rs = ps.executeQuery();
			list = jdbcUtil.extract(rs);
		} catch (SQLException se) {
			throw new SQLException("SQLException: " + se.getMessage());
		} catch (Exception ex) {
			Debug.logError(ex, module);
			throw new Exception(ex);
		} finally {
			if (rs != null)
				try {
					rs.close();
				} catch (SQLException quiet) {
				}
			if (ps != null)
				try {
					ps.close();
				} catch (SQLException quiet) {
				}
			if (c != null)
				try {
					c.close();
				} catch (SQLException quiet) {
				}
		}
		return list;
	}
679591
public <T> List<T> query(String sql, RowMapper<T> rowMapper) throws DataAccessException{
		//dynamic change catalog name
		sql = changeCatalog(sql);
		try{
			return jdbcTemplate.query(sql, rowMapper);
		}catch(DataAccessException e){
			logger.error("Error SQL: " + sql);
			throw e;
		}
	}
116991
public Collection<String> route(final String sql) {
        Collection<String> result = route(new SQLJudgeEngine(sql).judge().getType());
        if (showSQL) {
            SQLLogger.logSQL(sql, result);
        }
        return result;
    }
750214
@Override
    public PaginatedList queryForPaginatedList(String statementName, int pageSize)
            throws DataAccessException {
        return super.queryForPaginatedList(statementName, pageSize);
    }
359924
public List<Map<String, Object>> queryObjJoinDataByPageCondition(String innerSql, int start,int end) {

		/*		JdbcTemplate jdbcTemplate = (JdbcTemplate) MicroDbHolder
		.getDbSource(dbName);*/
		JdbcTemplate jdbcTemplate = getMicroJdbcTemplate();
		String sql = "";
		String tempType=calcuDbType();
		if(tempType!=null && tempType.equals("mysql")){		
		//if(dbType!=null && dbType.equals("mysql")){
			int pageRows=end-start;
			String limit=start+","+pageRows;
			sql=innerSql+ " limit "+limit;
		}else{
			String startLimit=" WHERE NHPAGE_RN >= "+start;
			String endLimit=" WHERE ROWNUM < "+end;
/*			if(orclEndFlag==false){
				endLimit=" WHERE ROWNUM < "+end;
			}*/
			sql="SELECT * FROM ( SELECT NHPAGE_TEMP.*, ROWNUM NHPAGE_RN FROM ("+ innerSql +" ) NHPAGE_TEMP "+endLimit+" ) "+ startLimit;
		}
		logger.debug(sql);
		List<Map<String, Object>> retList0 = jdbcTemplate.queryForList(sql);
		//add 201807 ning
		//List<Map<String, Object>> retList=changeOutKeyCase4List(retList0);	
		//add 201902 ning
		List<Map<String, Object>> retList=ignoreKeyCase((List)retList0);
		return retList;
	}
284478
private void setPageTotalCount(Connection connection, MappedStatement mappedStatement, BoundSql boundSql) {
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        try {
            preparedStatement = connection.prepareStatement(createCountSql(boundSql.getSql()));
            ParameterHandler parameterHandler = new DefaultParameterHandler(mappedStatement, boundSql.getParameterObject(), boundSql);
            parameterHandler.setParameters(preparedStatement);
            resultSet = preparedStatement.executeQuery();
            if (resultSet.next()) {
                ((PageEntity) boundSql.getParameterObject()).setTotalCount(resultSet.getLong(1));
            }
            if (resultSet != null) resultSet.close();
            if (preparedStatement != null) preparedStatement.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
775936
public Page<T> page(String sql, Object[] params, PageRow pageRow) {
        this.beforeCheck();
        Connection conn = getConn();
        try {
            String countSql = useSQL ? "SELECT COUNT(*) FROM (" + sql + ") tmp" : buildCountSQL(sql);

            long count = conn.createQuery(countSql)
                    .withParams(params)
                    .executeAndFetchFirst(Long.class);

            Page<T> pageBean = new Page<>(count, pageRow.getPageNum(), pageRow.getPageSize());

            ifThen(count > 0, () -> {
                String pageSQL = this.buildPageSQL(sql, pageRow);
                List<T> list = conn.createQuery(pageSQL)
                        .withParams(params)
                        .setAutoDeriveColumnNames(true)
                        .throwOnMappingFailure(false)
                        .executeAndFetch(modelClass);

                this.setJoin(list);
                pageBean.setRows(list);
            });

            return pageBean;
        } finally {
            this.closeConn(conn);
            this.clean(null);
        }
    }
1203107
public List<Entity> pageForEntityList(Entity where, int page, int numPerPage) throws SQLException {
		return pageForEntityList(where, new Page(page, numPerPage));
	}
274011
public String queryString(String sql, Object... params) throws SQLException {
		return query(sql, new StringHandler(), params);
	}
215714
@Deprecated
	public static ResultSet query(String sql, Object... args) {
		ResultSet result = null;
		Connection con = getconnnection();
		PreparedStatement ps = null;
		try {
			ps = con.prepareStatement(sql);
			if (args != null) {
				for (int i = 0; i < args.length; i++) {
					ps.setObject((i + 1), args[i]);
				}
			}
			result = ps.executeQuery();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return result;
	}
425305
public SqlStatement parse(String sql) {

        // does a cached parse result exist for this statement?
        if (_cachedSqlStatements.containsKey(sql)) {
            return _cachedSqlStatements.get(sql);
        }

        SqlGrammar _parser = new SqlGrammar(new StringReader(sql));
        SqlStatement parsed = null;
        try {
            parsed = _parser.parse();
        } catch (ParseException e) {
            throw new ControlException("Error parsing SQL statment." + e.getMessage(), e);
        } catch (TokenMgrError tme) {
            throw new ControlException("Error parsing SQL statment. " + tme.getMessage(), tme);
        }

        if (parsed.isCacheable()) {
            _cachedSqlStatements.put(sql, parsed);
        }
        return parsed;
    }
65967
private QueryParameters readResultSetRow(int row) throws SQLException {
        int currentRow = getCurrentResultSet().getRow();
        QueryParameters result = null;

        if (currentRow == 0) {
            // before first or last
            if (getCurrentResultSet().isAfterLast() == true) {
                // positioning on last
                getCurrentResultSet().last();
            } else if (getCurrentResultSet().isBeforeFirst() == true) {
                // position on first
                getCurrentResultSet().first();
            } else {
                throw new MjdbcRuntimeException("ResultSet need to be repositioned to get row different than zero");
            }

            currentRow = getCurrentResultSet().getRow();
        }

        if (currentRow == row) {
            result = convertResultSetCurrentLine(getCurrentResultSet());
        }
        if (useRelativePositioning == true) {

            getCurrentResultSet().relative(row - currentRow);

            if (getCurrentResultSet().getRow() > 0) {
                result = convertResultSetCurrentLine(getCurrentResultSet());
            }
        } else if (currentRow < row) {
            while (getCurrentResultSet().next() == true) {
                if (getCurrentResultSet().getRow() == row) {
                    result = convertResultSetCurrentLine(getCurrentResultSet());
                }
            }
        } else {
            while (getCurrentResultSet().previous() == true) {
                if (getCurrentResultSet().getRow() == row) {
                    result = convertResultSetCurrentLine(getCurrentResultSet());
                }
            }
        }

        return result;
    }
1152845
public Page<T> page(PageRow pageRow) {
        String sql = this.buildSelectSQL(false);
        return this.page(sql, pageRow);
    }
259615
public static ResultSetResult wrapQuery(Connection connection, String sql,
			String[] selectionArgs) {
		return new ResultSetResult(query(connection, sql, selectionArgs));
	}
1230361
public ResultSet executeQuery(String sql) throws SQLException {
    if (executeInternal(sql, fetchSize, Statement.NO_GENERATED_KEYS)) {
      return results.getResultSet();
    }
    return SelectResultSet.createEmptyResultSet();
  }
107061
public PageResult<Entity> page(Entity where, Page page, String... selectFields) throws SQLException{
		return db.page(Arrays.asList(selectFields), fixEntity(where), page);
	}