分页查询代码java java分页查询原理思路

java 中查询数据库后的分页咋做 , 管理系统的查询显示方面,上一页,下一页的实现数据库 分页分页查询代码java的查询语句为 select top pageSize * from objectTable obj where obj.id not in(select top (pageNumber-1)*pageSizeid from objectTable)然后将查询结果放到一个List集合中 返回回去 。在页面进行显示就可以分页查询代码java了 。但注意分页查询代码java的是页面要控制好当前页码 。pageSize分页查询代码java: 每页显示分页查询代码java的信息条数、pageNumber:当前页码
谁能给我个完整的java 分页代码 谢谢了import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import com.lqh.dao.db.DBCon;
public class PageDAO {
public static final String Text = "text";
public static final String Image = "image";
public static final String BbsText = "bbstext";
public static final String BbsImage = "bbsimage";
private HttpServletRequest request;
private int currentpage = 1; // 当前是第几页
private int pagecount = 0; // 一共有多少页
private int rscount = 0; // 一共有多少行
private int pagesize = 10; // 每页有多少行[默认为20行]
public PageDAO(HttpServletRequest request) {
this.request = request;
}
public int getCurrentpage() {
return currentpage;
}
public void setCurrentpage(int currentpage) {
this.currentpage = currentpage;
}
public int getPagecount() {
return pagecount;
}
public void setPagecount(int pagecount) {
this.pagecount = pagecount;
}
public int getPagesize() {
return pagesize;
}
public void setPagesize(int pagesize) {
this.pagesize = pagesize;
}
public int getRscount() {
return rscount;
}
public void setRscount(int rscount) {
this.rscount = rscount;
}
/**
* 传入SQL语句获取总记录数
*/
public int getRsCountForRs(String sql) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
DBCon dbcon=new DBCon();
try {
conn = dbcon.getConn();
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
if (rs.next()) {
rs.last();
this.rscount = rs.getRow();
} else {
this.rscount = 0;
}
} catch (Exception ex) {
ex.printStackTrace();
this.rscount = 0;
} finally {
dbcon.tryClose(rs, ps, conn);
}
return this.rscount;
}
public int getRsCountForSQL(String sql) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
DBCon dbcon=new DBCon();
try {
conn = dbcon.getConn();
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
if (rs.next()) {
this.rscount = rs.getInt("rscount");
} else {
this.rscount = 0;
}
} catch (Exception ex) {
ex.printStackTrace();
this.rscount = 0;
} finally {
dbcon.tryClose(rs, ps, conn);
}
return this.rscount;
}
/**
* 获取总页数
*
* @return int
*/
public int getPageCount() {
try {
this.pagecount = ((this.rscount - 1) / this.pagesize) + 1;
} catch (Exception ex) {
this.pagecount = 0;
}
return this.pagecount;
}
/**
* 获取当前页码分页查询代码java的设置
*
* @return int
*/
public int getCurrentPage() {
try {
if (this.request.getParameter("currentpage") != null
Integer.parseInt(this.request
.getParameter("currentpage"))1) {
this.currentpage = Integer.parseInt(this.request

推荐阅读