@SuppressWarnings("unchecked")
public List<TbInfo> searcherPage(final int typeInfo,final int pageNo,final int pageSize) {
List<TbInfo> list = getHibernateTemplate().executeFind(
new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException,SQLException{
final String hql="select info from TbInfo info,TbType ty where info.infoState='1' and info.infoPayfor='0' and info.tbType=ty and ty.typeSign=?";
Query query=session.createQuery(hql);
query.setInteger(0,typeInfo);
int firstResultIndex=pageSize*(pageNo-1);
query.setFirstResult(firstResultIndex);
query.setMaxResults(pageSize);
List<TbInfo> list=query.list();
return list;
}
}
);
return list;
}
当在数据库有数据是,能够正常运行,
但是当数据库没有值,就会出现这个异常
怎么解决呢 ?
public List<TbInfo> searcherPage(final int typeInfo,final int pageNo,final int pageSize) {
List<TbInfo> list = getHibernateTemplate().executeFind(
new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException,SQLException{
final String hql="select info from TbInfo info,TbType ty where info.infoState='1' and info.infoPayfor='0' and info.tbType=ty and ty.typeSign=?";
Query query=session.createQuery(hql);
query.setInteger(0,typeInfo);
int firstResultIndex=pageSize*(pageNo-1);
query.setFirstResult(firstResultIndex);
query.setMaxResults(pageSize);
List<TbInfo> list=query.list();
return list;
}
}
);
return list;
}
当在数据库有数据是,能够正常运行,
但是当数据库没有值,就会出现这个异常
怎么解决呢 ?
query.setFirstResult(firstResultIndex);
query.setMaxResults(pageSize);这个是从firstResultIndex行开始,取pageSize条数据,如果你数据库中没有数据,肯定会出异常了。