论坛首页 入门技术论坛

jsp中分页DAO代码

浏览 1304 次
该帖已经被评为新手帖
作者 正文
   发表时间:2008-06-25  
public static final String SEARCHSQLPageall =
"select"             + ENTER +
"  count(*) "       + ENTER +
"from "              + ENTER +
"    administrator"       + ENTER +
"where " + ENTER +
"   deleteFlg = 1";

public static final String SEARCHSQLFenye =
"select"             + ENTER  ;



public int getPageCount(int pageno){
ResultSet rs = DBmanager.executeQuery(SEARCHSQLPageall);
int pageCount=0;
int allinfo=0;
try {
while(rs.next()) {

allinfo = rs.getInt(1);
}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
if((allinfo%pageno)==0){
pageCount = (allinfo/pageno);
}else{
pageCount = (allinfo/pageno)+1;
}
return pageCount;
};


/**
*
* @param nowPage 当前的页码
* @param pageNo  每页行数
* @return
*/
public ArrayList<SysAdmin> findAllFenye(int nowPage, int pageNo) {
StringBuilder sql = new StringBuilder(SEARCHSQLFenye);
sql.append(" top " + pageNo);
sql.append(" admin_ID,admin_Name"+ ENTER ) ;
sql.append(" from administrator"+ ENTER ) ;
sql.append(" where deleteFlg = 1"+ ENTER ) ;
sql.append(" and admin_ID not in"+ ENTER ) ;
sql.append(" (select top"+ ENTER ) ;
sql.append( pageNo*(nowPage-1)+  "admin_ID   from administrator  where deleteFlg = 1 order by admin_ID asc)");
sql.append(" order by admin_ID asc");
ArrayList<SysAdmin> admins = new ArrayList<SysAdmin>();
ResultSet rs = DBmanager.executeQuery(sql.toString());
System.out.println(sql.toString());
try {
while(rs.next()) {
SysAdmin admin = new SysAdmin();
admin = new SysAdmin();
admin.setAdmin_ID(rs.getString("admin_ID"));
admin.setAdmin_Name(rs.getString("admin_Name"));
admins.add(admin);

}
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
return admins;
}




}
得到总行数,设置每页的大小,就OK了
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics