public <T> List<T> query(String sql, AbstractSqlParameterSource parameters,final int maxrows,final RowMapper<T> mapper){ return this.namedParameterJdbcTemplate.query(sql, parameters, new ResultSetExtractor<List<T>>(){ @Override public List<T> extractData(ResultSet rs) throws SQLException, DataAccessException { List<T> data = new ArrayList<T>(); if(rs==null) return data; int rowNum = 0; while((maxrows>0 && rowNum<maxrows || maxrows<0) && rs.next()){ data.add(mapper.mapRow(rs, rowNum++)); } return data; } }); }