Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java EE 综合讨论区 » Hibernate  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 数据库实现分页
zhbsoft





发贴: 1
积分: 0
于 2009-10-16 22:35 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我是一位J2EE新手,最近在做一个微博客系统,现在涉及到了从数据库中查询数据后的分页问题,请问哪位高手仁兄能为我简单明了的讲解一下。
while(true){
System.out.println("非常感谢!");
}



作者 Re:数据库实现分页 [Re:zhbsoft]
xudagehao





发贴: 1
积分: 0
于 2009-10-24 20:26 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我给你一个较简单的分页方法

public List check_all_information(int titleID,int onepagecount,int thispage) {
    //titleID是指我的这个sql语句要得一个参数而已,你根据 实 际情况吧
//onepagecount是 你想一页中显示多少条记录
//thispage是指你的网页处于第几页
new jdbc();
    List list = new ArrayList();
//设置开始标记
    int begin=(thispage-1)*onepagecount+1;
//结束标记
    int end=thispage*onepagecount;
    int count=0;
    
    String sql="select username,txt,user_face,data from user_in where titleID=?";
    PreparedStatement stmt=jdbc.getPreparedStatement(sql);
    try {
      stmt.setInt(1, titleID);
      ResultSet rs= stmt.executeQuery();
      while(rs.next()){
//设置一个标记count来计数得到多少条路
        count++;
        if(count<begin){//当count小于begin标 记的值时,循环继续
          continue;
        }
        if(count>end){
//当count值大于end值时跳出循环
          break;
        }

        //实例一个bean对象
        user_in u= new user_in();
        String username=rs.getString(1);
        String txt=rs.getString(2);
        String user_face=rs.getString(3);
        String data=rs.getString(4);
        
        u.setUsername(username);
        u.setTxt(txt);
        u.setUser_face(user_face);
        u.setData(data);
//把这个对象放入List列表中
        list.addBroken heart...;
      }
//关闭数据库连接, jdbc类为另一个类封装了数据库操作的一个类
      jdbc.close();
      jdbc.close(stmt);
    } catch (SQLException e) {
      e.printStackTrace();
    }
    
    return   list;
  }



作者 Re:数据库实现分页 [Re:zhbsoft]
liyingjie1





发贴: 3
积分: 0
于 2009-10-25 14:31 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你便用 hibernate 框架了吗?

如果便用了 可便 直接实现分页



作者 Re:数据库实现分页 [Re:zhbsoft]
liyingjie1





发贴: 3
积分: 0
于 2009-10-25 14:34 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
q.setFirstResult

q.setMaxResult




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923