日期:2014-05-18  浏览次数:20763 次

Query query=session.createQuery(strBuffer.toString)出错。请帮帮我。谢谢
Action
public ActionForward pageList(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response){
String name=request.getParameter("name");
String posttime=request.getParameter("posttime");
String pNo=request.getParameter("pageNo");
Note_ApplyDAO noteDAO=new Note_ApplyDAO();
Pagination page=noteDAO.pageList(name, posttime, pNo);
request.setAttribute("pageBean", page);
List list = page.getDataList();
request.setAttribute("name", name);
request.setAttribute("posttime", posttime);
request.setAttribute("list", list);
return mapping.findForward("list");
}
DAO:
public Pagination pageList(String name, String posttime, String pNo) {
int pageNo = 0;
Pagination page = new Pagination();
StringBuffer strBuffer = new StringBuffer();

if (name != null && name.trim().length() > 0) {
strBuffer.append("where name ='" + name + "'");
}
if (posttime != null && posttime.trim().length() > 0) {
Date posttime1 = Date.valueOf(posttime);
strBuffer.append("where posttime='" + posttime1 + "'");
}
//system.out.println(strbuffer.tostring());
if (pNo != null && pNo.length() > 0) {
pageNo = Integer.valueOf(pNo);
}

page = page.getData(Note_Apply.class,strBuffer.toString(), pageNo);

return page;
}
Pagination:
public Pagination getData(Class c,String whereSql,int PageNo){
Session session = null;
List list = null;
int allCount = 0;
Pagination page = new Pagination();
session = HibernateUtils.getCurrentSession();

// 组装sql语句,查询总记录数
StringBuffer sqlbuffer = new StringBuffer( "select count(*) from " + c.getName( ) );
if ( whereSql != null ) {
sqlbuffer.append( whereSql );
}
session = HibernateUtils.getCurrentSession();
try {
Query qRows = session.createQuery( sqlbuffer.toString() );
Iterator iterator = qRows.iterate( );
// 得到总记录数
allCount =(Integer)iterator.next( );
sqlbuffer = new StringBuffer( "from " + c.getName( ) );
if ( whereSql != null ) {
sqlbuffer.append( whereSql );
}

// 得到数据集
Query queryList = session.createQuery( sqlbuffer.toString( ) );
queryList.setFirstResult( pageSize*PageNo-pageSize );
queryList.setMaxResults( pageSize );
list =queryList.list( );
page.setDataList(list);
//设置总记录数
page.setRowsCount(allCount);

//设置当前页
if(PageNo==0){
page.setCurPage( 1 );
}else{
page.setCurPage( PageNo );
}
// 设置总页数
if ( page.getRowsCount()% this.pageSize == 0 ) {
page.setMaxPage( page.rowsCount/ this.pageSize );
} else {
page.setMaxPage( page.rowsCount / this.pageSize + 1 );
}
}catch(HibernateException e){
e.printStackTrace();
}
return page;
}
问题:Query queryList = session.createQuery( sqlbuffer.toString( ) );如果有条件的话这句话就会出错。
javax.servlet.ServletException: javax.servlet.ServletException: java.lang.NoSuchMethodError: org.hibernate.hql.antlr.HqlBaseParser.recover(Lantlr/RecognitionException;Lantlr/collections/impl/BitSet;)V<