java应用中两个问题解决方法.doc_第1页
java应用中两个问题解决方法.doc_第2页
java应用中两个问题解决方法.doc_第3页
java应用中两个问题解决方法.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

一、多表查询分页方法一:public List getUserlist(String userAccount,String EmployeeFullName, int startNum,int pagelength) int totalResults; /总记录的条数 String condition=; if(!userAccount.equals()&!EmployeeFullName.equals() condition= and sysuser.susUseraccount like%+userAccount+% or employee.coeFullname like%+EmployeeFullName+%; else if(!EmployeeFullName.equals()&userAccount.equals() condition= and employee.coeFullname like%+EmployeeFullName+%; else if(!userAccount.equals()&EmployeeFullName.equals() condition= and sysuser.susUseraccount like%+userAccount+%; String hql =select employee.coeEmployeeid,employee.coeFullname,employee.coeSexuality,employee.coePictureurl,sysuser.susAccountid, sysuser.susUseraccount, sysuser.susForumUsersLevel from SmcSystemuser sysuser,HrmEmployee employee where sysuser.susEmployeeid=employee.coeEmployeeid +condition+ order by sysuser.susAccountid; System.out.println(hql:+hql); List res = new Vector();/ 将用于存放保存的结果集合 Session session = null; ScrollableResults srs = null; try /得到一个Hibernate Session /分页关键语句 session = this.getSessionFactory().openSession(); /下面创建一个匿名Query实例并调用它的scroll()方法返回以 /ScrollableResults形式组织的查询结果 Query query = session.createQuery(hql); query.setFirstResult(startNum); query.setMaxResults(pagelength); srs = query.scroll(); / 将查询结果放入List保存 int i=0; while(srs.next() i+; res.add(new EmpUsrAccountBean(srs.getString(0), srs.getString(1), srs.getString(2), srs.getString(3), srs.getString(4), srs.getString(5), srs.getString(6); catch(HibernateException he) if(srs!=null) try srs.close(); catch(Exception e) System.out.println(e.getMessage(); System.out.println(he.getMessage(); finally try session.close(); catch(Exception e) System.out.println(e.getMessage(); return res; 错误:在执行到srs = query.scroll(); 报如下错误ERROR AssertionFailure an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)org.hibernate.AssertionFailure: scrollable result sets are not enabledat org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:413)原因分析:jboss里没有连结数据库的驱动解决办法:在jboss目录下的serverdefaultlib中加入数据库驱动方法二:将获取的值存入一个新的list对象中,在页面中list(list数组)取值public List getEmplistByName(String empName,int offset,int length) List emplist=new ArrayList();String hql=;try if(empName.equals()hql=select new list(emp,org) from HrmEmployee emp,HrmOrganizations org where emp.coeBelongdepid=org.cooOrganizationid order by emp.coeEmployeeid;else hql=select new list(emp,org) from HrmEmployee emp,HrmOrganizations org where emp.coeBelongdepid=org.cooOrganizationid and emp.coeFullname like%+empName+% order by emp.coeEmployeeid;return getListForPage(hql, offset,length) ; catch (DataAccessException e) e.printStackTrace();return emplist;页面中取值为$emplist0.coeFullname二、配

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论