mysql在JSP页面中分页查看的解决(3)
PASSWORD);
String sqlCount = "select count(*) from employee";//得到一共有多少条记录
PreparedStatement ps = conn.prepareStatement(sqlCount);
ResultSet rs = ps.executeQuery();
int recordCount = 0;//一共有多少记录
if (rs.next()) {
recordCount = rs.getInt(1);
}
%>
<%
//获取分页对象,传参
String pageStr = request.getParameter("page");
int currentPage = 1;
if (pageStr != null) {
currentPage = Integer.parseInt(pageStr);
}
View view = new View(5, recordCount, currentPage);
//获取参数
int fromIndex = view.getFromIndex();//起始位置
int pageSize = view.getPageSize();//每页显示的记录数
%>
<table border="1">
<%
//执行sql
String sql = "select fname,lname from employee limit ?,?";
ps = conn.prepareStatement(sql);
ps.setInt(1, fromIndex);
相关新闻>>
- 发表评论
-
- 最新评论 更多>>