jsp多表查询分页

yca8530844 2009-09-07 06:56:09
多表查询出来的数据怎么分页最好
...全文
102 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zpls2003 2009-09-14
  • 打赏
  • 举报
回复
查询的时候用LEFT JOIN效率最高!
Stephen_Kang 2009-09-14
  • 打赏
  • 举报
回复
public List findAllBookByPage(int page) {
List list = new ArrayList();
conn = this.getConn();
int rows = 0;
if(page > 1){
rows = (page-1)*5;
}
String sql = "select top 5 * from books inner join bookType on books.ids=bookType.id where ids not in (select top "+rows+" ids from books inner join bookType on books.ids=bookType.id order by ids asc) order by ids asc";
try {
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()){
int ids = rs.getInt(1);
String bookName = rs.getString(2);
String author = rs.getString(3);
String descs = rs.getString(4);
int bid = rs.getInt(5);
Book book = new Book(ids,bookName,author,descs,bid);
list.add(book);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
this.closeAll(conn, pstmt, rs);
}
return list;
}

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧