81,092
社区成员
发帖
与我相关
我的任务
分享
<% Class.forName("com.mysql.jdbc.Driver").newInstance();
String url="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=gb2312";
String username="root";
String password="19870626";
Connection conn=DriverManager.getConnection(url,username,password);
int intPageSize;//一页显示的记录数
int intRowCount;//记录总数
int intPageCount;//总页数
int intPage;//待显示的页码
String strPage;
int i;
intPageSize=6;
strPage=request.getParameter("page");
if(strPage==null){
intPage=1;
}
else{
intPage=Integer.parseInt(strPage);
if(intPage<1)intPage=1;
}
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from book";
ResultSet rs=stmt.executeQuery(sql);
rs.last();
intRowCount=rs.getRow();
intPageCount=(intRowCount+intPageSize-1)/intPageSize;//就是总页数
if(intPage>intPageCount){
intPage=intPageCount;
}
if(intPageCount>0){
rs.absolute((intPage-1)*intPageSize+1);//将记录指针定位到待显示页的第一条记录
i=0;
while(i<intPageSize&&!rs.isAfterLast()){%>
<tr>
<td><%=rs.getString("book_id") %></td>
<td><%=rs.getString("book_name") %></td>
<td><%=rs.getString("book_author") %></td>
<td><%=rs.getString("book_source") %></td>
<td><%=rs.getString("book_date") %></td>
<td><%=rs.getString("book_price") %></td>
<td><a href="update.jsp">修改</a> <a href="delete.jsp">删除</a></td>
</tr>
<% rs.next();
i++;
}
}
%>
</table>
<hr color="#999999">
<div align="center">第<%=intPage %>页 共<%=intPageCount %>页
<%if(intPage<intPageCount){ %>
<a href="book_mes.jsp?page=<%=intPage+1 %>">下一页</a>
<%} %>
<%if(intPage>1){ %>
<a href="book_mes.jsp?page<%=intPage-1 %>">上一页</a>
<%} %>
<%
rs.close();
stmt.close();
conn.close();
%>