用PrepareStatement方法的纯JSP版分页(Mysql数据库)
2012-01-16 18:07
176 查看
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>JSP版分页</title> </head> <body> <%! int pagecount; // pagecount为总页数 int pagesize=3;%> <%-- pagesize为每页显示的记录数 --%> <% Connection con; Class.forName("com.mysql.jdbc.Driver"); con=DriverManager.getConnection("jdbc:mysql://localhost/qinshi","root","007"); String sql="select * from wowo order by id"; PreparedStatement ps=con.prepareStatement(sql,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY); ResultSet rs=ps.executeQuery(); rs.last(); int count=rs.getRow(); //count为记录总数 int i=0; int pageI=1 ; pagecount=(count%pagesize==0)?(count/pagesize):(count/pagesize+1); %> <% String pages=request.getParameter("nowpage"); if(pages==null) pages="1"; try{ pageI = Integer.parseInt(pages); } catch (NumberFormatException e){ pageI = 1; } if(pageI<0||pageI>pagecount) { pageI=pagecount;} int position=(pageI-1)*pagesize +1; rs.absolute(position); %> <table border="1" cellpadding="0" cellspacing="0"><tr> <th>id</th> <th>users</th> </tr> <% while(i<pagesize&&!rs.isAfterLast()){ %> <tr> <td><%=rs.getString(1)%></td> <td><%=rs.getString(2)%></td> </tr> <%rs.next();i++;}%> </table> <form method="get" action=""> <table> <tr> <td><a href="fenye.jsp?nowpage=1">第一页</a></td> <td><% if(pageI<pagecount){%> <a href="fenye.jsp?nowpage=<%=pageI+1 %>">下一页</a><%}%></td> <td><% if(pageI>1){%> <a href="fenye.jsp?nowpage=<%=pageI-1 %>">上一页</a><%}%></td> <td><a href="fenye.jsp?nowpage=<%=pagecount %>">尾页</a></td> <td><input type="text" name="nowpage" /></td> <td><input type="submit" name="submit" value="go"/></td></tr> </table> </form> </body> </html> |
相关文章推荐
- 在jsp中对mysql数据库分页的方法
- 在jsp中对mysql数据库分页的方法
- jsp+mysql数据库操作常用方法实例总结
- 【韩顺平jsp教程笔记一】MySql下关于分页时取出前几条记录方法(不同于SqlServer)
- 在JSP页面调用JAVA方法实现MySQL数据库的备份和恢复
- java分页代码用于jsp及java并带有测试方法
- Jsp分页技术直接分页的简单方法
- 一个用JSP实现的分页的类及调用方法
- 一个用JSP实现的分页的类及调用方法
- 一个用JSP实现的分页的类及调用方法
- 分页显示问题的解决方法(jsp,sqlserver,mysql,oracle)
- 在JSP页面中使用JDBC连接MySQL数据库的方法
- 一个用JSP实现的分页的类及调用方法
- JSP实现HTML网页中分页查询Mysql数据库数据
- 一个用JSP实现的分页的类及调用方法
- jsp的分页查询代码(mysql数据库)
- 一个用JSP实现的分页的类及调用方法
- 分页显示问题的解决方法(jsp,sqlserver,mysql,oracle)
- jsp+servlet+javabean实现数据分页方法完整实例
- jsp+servlet+javabean实现数据分页方法完整实例