MySQL数据库中正确实现分页显示的代码示例

 2022-10-27    334  

以下的文章主要描述的是在MySQL数据库中正确实现分页显示的实际应用代码,如以下所示,以下就是对MySQL数据库中正确实现分页显示的实际应用代码的描述,希望在你今后的学习中会对你有所帮助。

publicList<Product>getProducts(intpageNo,intpageSize) 
{ 
Connectionconn=null; 
ResultSetrs=null; 
List<Product>list=newArrayList<Product>(); 
conn=DB.getConn(); 
Stringsql="select*fromproductlimit"+(pageNo-1)*pageSize+","+pageSize; 

rs=DB.executeQuery(conn,sql); 
try 
{ 
while(rs.next()) 
{ 
Productp=newProduct(); 
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(SQLExceptione) 
{ 
e.printStackTrace(); 
} 
finally 
{ 
DB.closeRs(rs); 
DB.closeConn(conn); 
} 
returnlist; 
}

MySQL数据库中正确实现分页显示的代码示例

  •  标签:  
  • MySQL
  •  

原文链接:https://77isp.com/post/9881.html

=========================================

https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。