MYsql自定义分页

来源:互联网 发布:网络依赖症的危害 编辑:程序博客网 时间:2024/06/06 01:24

    public List<Product> getProducts(int pageNo, int pageSize)
    {
        Connection conn=null;
        ResultSet rs=null;
        List<Product> list=new ArrayList<Product>();
        conn=DB.getConn();
        String sql="select * from product limit "+(pageNo-1)*pageSize+","+pageSize;

        rs=DB.executeQuery(conn, sql);
        try
        {
            while(rs.next())
            {
                Product p=new Product();
                p.setId(rs.getInt("id"));
                p.setName(rs.getString("name"));
                p.setDescr(rs.getString("descr"));
                p.setNormalPrice(rs.getDouble("normalprice"));
                p.setMemberPrice(rs.getDouble("memberprice"));
                p.setCategoryId(rs.getInt("categoryid"));
                p.setPdate(rs.getTimestamp("pdate"));
                list.add(p);
            }
        } catch (SQLException e)
        {
            e.printStackTrace();
        }
        finally
        {
            DB.closeRs(rs);
            DB.closeConn(conn);
        }
        return list;
    }

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/cjmiou/archive/2008/11/17/3317735.aspx

原创粉丝点击