MySQL數(shù)據(jù)庫中正確實現(xiàn)分頁顯示的代碼示例
作者:佚名
我們今天主要介紹的是MySQL數(shù)據(jù)庫中正確實現(xiàn)分頁顯示的實際應用代碼,有了這張代碼圖,相信你在以后的學習中會收益不少。
以下的文章主要描述的是在MySQL數(shù)據(jù)庫中正確實現(xiàn)分頁顯示的實際應用代碼,如以下所示,以下就是對MySQL數(shù)據(jù)庫中正確實現(xiàn)分頁顯示的實際應用代碼的描述,希望在你今后的學習中會對你有所幫助。
- 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;
- }
上述的相關內(nèi)容就是對MySQL數(shù)據(jù)庫中實現(xiàn)分頁顯示的代碼的描述,希望會給你帶來一些幫助在此方面。
【編輯推薦】
責任編輯:佚名
來源:
博客園