不同数据库有不同的写法 这个好像更应该是sql怎么写 而不是java怎么写啊

解决方案 »

  1.   

    我用的mysql  
     我是想用JAVA 代码 循环控制分页
      

  2.   

    sql的分页的问题吧,每个数据库都不一样的!
      

  3.   

    mysql记得好像是limit n,m来控制的
      

  4.   

    对于mysql
    LIMIT子句可以用来限制由SELECT语句返回过来的数据数量,它有一个或两个参数,如果给出两个参数, 
    第一个参数指定返回的第一行在所有数据中的位置,从0开始(注意不是1),第二个参数指定最多返回行 
    数。例如: 
    select * from table LIMIT 5,10; #返回第6-15行数据 
    select * from table LIMIT 5; #返回前5行 
    select * from table LIMIT 0,5; #返回前5行 
      

  5.   

    其实最好sql分页java的话速度会慢的如果java分页要个算法了。
    比如
    if(pageNum < pageSum-1){
    for (int i = startNum; i < startNum + rowNum; i++) {
    pageList.add(list.get(i));
    }
    }else{
    if(list.size()==rowNum||rowNum==1 || list.size()%rowNum==0){
    for (int i = startNum; i < startNum + rowNum; i++) {
    pageList.add(list.get(i));
    }
    }else{
    for (int i = startNum; i < startNum + list.size()%rowNum; i++) {
    pageList.add(list.get(i));
    }
    }
    }
      

  6.   


    我知道mysql 是 limit 分页!  我现在的问题是要limit  后面的字符串要循环变动
    如 100条我每次去30跳的话limit 后面的数据变成
     limit 0,30
     limit 30,60
     limit 60,90
     limit 90,100
      

  7.   

    int count//次数
    //传进来count
    if(count==4)
    sql="select * from table LIMIT 90,100";
    else{
    sql="select * from table LIMIT "+(30*(count-1))+","+(30*count);
    }
      

  8.   

    currentPage //当前页
    rowsPerPage //每页显示的记录的条数
    select * from table limit (currentPage-1)*rowsPerPage,rowsPerPage;
      

  9.   

    final int offset = 30;
    int startIndex = 0;
    int length = 100;//select count(*) from table的结果值。
    while(startIndex+offset<length){
      executeSQL(startIndex,offset);
      startIndex+=offset;
    }
    executeSQL(startIndex,length-startIndex);
    public void executeSQL(int startIndex,int offset){
      String sql = "select * from table limit "+startIndex+", "+offset;
      //...
    }