0

次の SQL を実行すると、予想される並べ替え順序 (last_run_date、昇順) でデータが返されます。

select * from ( select a.*, ROWNUM rnum from ( select id, job_name, description, enabled, last_run_date, last_run_msg, current_status, userid from JOBS ORDER BY last_run_date asc ) a   where ROWNUM <= 5 ) where rnum > 0

ただし、次の Java/Spring コードを実行すると、データが指定された並べ替え順序になっていません。

private final String GET_ALL_JOBS_JQGRID_SQL = "select * from " +
            "( select a.*, ROWNUM rnum from " + 
            "( select id, job_name, description, enabled, last_run_date, last_run_msg, current_status, userid from JOBS ORDER BY :sidx asc ) a " + 
            "  where ROWNUM <= :max_row_to_fetch ) " +
            "where rnum > :min_row_to_fetch";

private NamedParameterJdbcTemplate jobStatusParameterJdbcTemplate;

public void setDataSource(DataSource dataSource) {

        this.dataSource = dataSource;

        this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);

        this.jobStatusParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
    }

パラメータ値として last_run_date、10、および 0 を渡します。

public List<Job> getAllJobs(String sidx, int max_row_to_fetch, int min_row_to_fetch) {

        SqlParameterSource namedParameters = new MapSqlParameterSource("sidx", sidx)
        .addValue("max_row_to_fetch", max_row_to_fetch)
        .addValue("min_row_to_fetch", min_row_to_fetch);


        @SuppressWarnings("unchecked")
        List <Job> jobs = jobStatusParameterJdbcTemplate.query(GET_ALL_JOBS_JQGRID_SQL, namedParameters, new JobRowMapper());

        return jobs;
    }

private static class JobRowMapper implements RowMapper
    {
        public Object mapRow(ResultSet rs, int arg1) throws SQLException 
        {
            int jobId = rs.getInt(1);

            String jobName = rs.getString(2);
            String jobDesc = rs.getString(3);
            String jobEnabled = rs.getString(4);
            Date jobLastRunDate = rs.getDate(5);
            String jobLastRunMsg = rs.getString(6);
            String jobCurrentStatus = rs.getString(7);
            String userid = rs.getString(8);

            Job job = new Job();
            job.setId(jobId);
            job.setJob_name(jobName);
            job.setDescription(jobDesc);
            job.setEnabled(jobEnabled);
            job.setLast_run_date(jobLastRunDate);
            job.setLast_run_msg(jobLastRunMsg);
            job.setCurrent_status(jobCurrentStatus);
            job.setUserid(userid);

            return job;
        }
4

0 に答える 0