在MYSQL中实现分页显示的代码--SHOPPING

来源:互联网 发布:防伪电子印章软件 编辑:程序博客网 时间:2024/05/22 13:36
  1.     public List<Product> getProducts(int pageNo, int pageSize)
  2.     {
  3.         Connection conn=null;
  4.         ResultSet rs=null;
  5.         List<Product> list=new ArrayList<Product>();
  6.         conn=DB.getConn();
  7.         String sql="select * from product limit "+(pageNo-1)*pageSize+","+pageSize;
  8.         rs=DB.executeQuery(conn, sql);
  9.         try
  10.         {
  11.             while(rs.next())
  12.             {
  13.                 Product p=new Product();
  14.                 p.setId(rs.getInt("id"));
  15.                 p.setName(rs.getString("name"));
  16.                 p.setDescr(rs.getString("descr"));
  17.                 p.setNormalPrice(rs.getDouble("normalprice"));
  18.                 p.setMemberPrice(rs.getDouble("memberprice"));
  19.                 p.setCategoryId(rs.getInt("categoryid"));
  20.                 p.setPdate(rs.getTimestamp("pdate"));
  21.                 list.add(p);
  22.             }
  23.         } catch (SQLException e)
  24.         {
  25.             e.printStackTrace();
  26.         }
  27.         finally
  28.         {
  29.             DB.closeRs(rs);
  30.             DB.closeConn(conn);
  31.         }
  32.         return list;
  33.     }
原创粉丝点击