我用以下方法从数据库查到一页有20项的数据,结果可以正确显示,但是会提示:Invalid operation for the current cursor position.里面我有用rs.next()啊
public ArrayList getData(String currentPage){
DataBase DB=new DataBase();
PageBean PB=new PageBean();

int rowCount=getRowCount();
int pageCount=getPageCount(rowCount);
ArrayList data=new ArrayList();

this.currentPage=Integer.parseInt(currentPage);
sql="select top 20 * from student where stu_id not in (select top "+(this.currentPage-1)*20+" stu_id from student)";
try{
DB.openconn();
rs=DB.executeQuery(sql);

while(rs.next()){
StuBean SB=new StuBean();
SB.setStu_id(rs.getString(1));
SB.setStu_name(rs.getString(2));
SB.setStu_sex(rs.getString(3));
SB.setBirthday(rs.getString(4));
SB.setPhone(rs.getString(5));
SB.setAddress(rs.getString(6));
SB.setClass_id(rs.getString(7));
data.add(SB);

}
}
catch(Exception e){
System.out.println(e.getMessage());
}
finally{
DB.closestmt();
DB.closeconn();
} return data;
}

解决方案 »

  1.   

    把rs暂存一下,你试一试。ResultSet rs1;
    while((rs1=rs.next())!=null){
           StuBean SB=new StuBean();
           SB.setStu_id(rs1.getString(1));
           SB.setStu_name(rs1.getString(2));
    }
      

  2.   

    1楼的朋友,rs.next()是布尔型啊,怎么可以赋给rs1呢
      

  3.   


    哦,sorry!当我没说!我是想提示你把rs先暂存一下,不知道具体怎么做!
      

  4.   

    做个测试吧~int count = 0;
    while(rs.next()){
                    StuBean SB=new StuBean();
                    SB.setStu_id(rs.getString(1));
                    SB.setStu_name(rs.getString(2));
                    SB.setStu_sex(rs.getString(3));
                    SB.setBirthday(rs.getString(4));
                    SB.setPhone(rs.getString(5));
                    SB.setAddress(rs.getString(6));
                    SB.setClass_id(rs.getString(7));
                    data.add(SB);
                    count++;
                }
    System.out.println("Count is :"+count);lz可以去测试下,我觉得最后结果应该是21,不知道是不是