以下的文章主要描述的是在MySQL数据库中正确实现分页显示的实际应用代码,如以下所示,以下就是对MySQL数据库中正确实现分页显示的实际应用代码的描述,希望在你今后的学习中会对你有所帮助。 publicList Product getProducts(intpageNo,intpageSize) { Conn
以下的文章主要描述的是在MySQL数据库中正确实现分页显示的实际应用代码,如以下所示,以下就是对MySQL数据库中正确实现分页显示的实际应用代码的描述,希望在你今后的学习中会对你有所帮助。
<ol class="dp-xml"> <li class="alt"><span><span>public List</span><span class="tag"><span class="tag-name">Product</span><span class="tag">></span><span> getProducts(int pageNo, int pageSize) </span></span></span></li> <li><span>{ </span></li> <li class="alt"> <span>Connection </span><span class="attribute">conn</span><span>=</span><span class="attribute-value">null</span><span>; </span> </li> <li> <span>ResultSet </span><span class="attribute">rs</span><span>=</span><span class="attribute-value">null</span><span>; </span> </li> <li class="alt"> <span>List</span><span class="tag"><span class="tag-name">Product</span><span class="tag">></span><span> </span><span class="attribute">list</span><span>=</span><span class="attribute-value">new</span><span> ArrayList</span><span class="tag"><span class="tag-name">Product</span><span class="tag">></span><span>(); </span></span></span> </li> <li> <span class="attribute">conn</span><span>=</span><span class="attribute-value">DB</span><span>.getConn(); </span> </li> <li class="alt"> <span>String </span><span class="attribute">sql</span><span>=</span><span class="attribute-value">"select * from product limit "</span><span>+(pageNo-1)*pageSize+","+pageSize; </span> </li> <li><span> </span></li> <li class="alt"> <span class="attribute">rs</span><span>=</span><span class="attribute-value">DB</span><span>.executeQuery(conn, sql); </span> </li> <li><span>try </span></li> <li class="alt"><span>{ </span></li> <li><span>while(rs.next()) </span></li> <li class="alt"><span>{ </span></li> <li> <span>Product </span><span class="attribute">p</span><span>=</span><span class="attribute-value">new</span><span> Product(); </span> </li> <li class="alt"><span>p.setId(rs.getInt("id")); </span></li> <li><span>p.setName(rs.getString("name")); </span></li> <li class="alt"><span>p.setDescr(rs.getString("descr")); </span></li> <li><span>p.setNormalPrice(rs.getDouble("normalprice")); </span></li> <li class="alt"><span>p.setMemberPrice(rs.getDouble("memberprice")); </span></li> <li><span>p.setCategoryId(rs.getInt("categoryid")); </span></li> <li class="alt"><span>p.setPdate(rs.getTimestamp("pdate")); </span></li> <li><span>list.add(p); </span></li> <li class="alt"><span>} </span></li> <li><span>} catch (SQLException e) </span></li> <li class="alt"><span>{ </span></li> <li><span>e.printStackTrace(); </span></li> <li class="alt"><span>} </span></li> <li><span>finally </span></li> <li class="alt"><span>{ </span></li> <li><span>DB.closeRs(rs); </span></li> <li class="alt"><span>DB.closeConn(conn); </span></li> <li><span>} </span></li> <li class="alt"><span>return list; </span></li> <li><span>} </span></li> </ol>
上述的相关内容就是对MySQL数据库中实现分页显示的代码的描述,希望会给你带来一些帮助在此方面。