小弟最近碰到一个数据上百万的分页查询,数据库是sqlservler2000的。而查询语句中要带有条件(多条件)。写了好久都没有达到想要的效果。希望大家帮帮忙?如果有比较好的分页sql 或者 分页存储过程(希望能讲的详细一点,在JAVA中如果调用。。该注意哪些)。。

解决方案 »

  1.   

    public static final int PAGE_NUM=6;//定义一个网页要显示商品的数量

    /**
     * 分页显示:得到某一页的List
     * @param page 页码
     * @return
     */
    public static  List getFenYeList(int page){
    int rowBegin=0;
    if(page>1){
    rowBegin=PAGE_NUM*(page-1);
    }
    List<FoodInfo> list=new ArrayList<FoodInfo>();
    String sql=String.format("select top(%d) * from foodInfo where foodID not in(select top(%d) foodID from foodInfo)",Service.PAGE_NUM,rowBegin);
    // 调用DAO中的方法得到Result数据集
    Result result=BaseDAO.runSelectSql(sql);

    if(result.getRowCount()>0){
    Map[] rows=result.getRows();
    for(Map row:rows)
    {
    .........
    list.add(..);
    }
    }
    return list;

    }
    然后在页面中调用此方法
      

  2.   


    写分页面是有集中办法:  个人觉得 多添加一个字段来分页比较好 多条件查询:
             注意尽量不要使用 distinct in 这些          可以 是用exsits来提高 查询 效率
      

  3.   

    分页其实没有你想像的那么麻烦
    写什么存储过程
    直接sql语句就搞定了
    查询10条到20条之间的关系
    select * from 表名  where id not in (select id  from 表名 where     。) 
    再加上你的top就可以了
    不懂可以进我的群
    QQ76208671
      

  4.   

    分页其实没有你想像的那么麻烦
    写什么存储过程
    直接sql语句就搞定了
    查询10条到20条之间的关系
    select * from 表名  where id not in (select id  from 表名 where     。) 
    再加上你的top就可以了
    不懂可以进我的群
    QQ76208671
      

  5.   

    String sql="select top 20 * from TBL_reply where TOPICID="+topicId
    +" and topicid not in  " +
    "(select top "+rowBegin+ " replyId from tbl_reply where topicid ="+topicId+" order by publishTime DESC) " +
    "order by publishtime DESC ";
      

  6.   

    分页一般采用sql分页和结果集分页结合起来使用
      

  7.   

    直接用ORACLE的ROWNUM来进行数据分页的计算比较方便吧