我用以下方法从数据库查到一页有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;
}
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;
}
while((rs1=rs.next())!=null){
StuBean SB=new StuBean();
SB.setStu_id(rs1.getString(1));
SB.setStu_name(rs1.getString(2));
}
哦,sorry!当我没说!我是想提示你把rs先暂存一下,不知道具体怎么做!
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,不知道是不是