public List search(GuestBook gb,String KeyWord,String isadmin){
session= HSF.currentSession(); System.out.println("开始搜索");
//Transaction表示一组对DB的交易
tx = session.beginTransaction();
Query query = session.createQuery("from LeaveWord l where l.ID in ("+gb.getIds()+") and l.levwTitle like '%"
+KeyWord+"%' and ifShow in (0"+isadmin+") order by levwDate desc");
System.out.println(query);
System.out.println(query);
List lwList =null;
try {
lwList=query.list();
System.out.println("已经查找到了留言LIST");
} catch (HibernateException e) {
e.printStackTrace();
}
Iterator iterator = lwList.iterator();
while(iterator.hasNext()) {
}
return lwList;
}高手请帮我看看这个方法,为什么能够查询到字母和数字,却查询不到中文的呢?谢谢了
session= HSF.currentSession(); System.out.println("开始搜索");
//Transaction表示一组对DB的交易
tx = session.beginTransaction();
Query query = session.createQuery("from LeaveWord l where l.ID in ("+gb.getIds()+") and l.levwTitle like '%"
+KeyWord+"%' and ifShow in (0"+isadmin+") order by levwDate desc");
System.out.println(query);
System.out.println(query);
List lwList =null;
try {
lwList=query.list();
System.out.println("已经查找到了留言LIST");
} catch (HibernateException e) {
e.printStackTrace();
}
Iterator iterator = lwList.iterator();
while(iterator.hasNext()) {
}
return lwList;
}高手请帮我看看这个方法,为什么能够查询到字母和数字,却查询不到中文的呢?谢谢了
检查下你的KeyWord里的中文正常吗?是不是乱码?是的话转一下码就OK啦.
public List search(GuestBook gb,String KeyWord,String isadmin){
session= HSF.currentSession(); System.out.println("开始搜索");
//Transaction表示一组对DB的交易
tx = session.beginTransaction();
Query query = session.createQuery("from LeaveWord l where l.ID in ("+gb.getIds()+") and l.levwTitle like '%" +KeyWord+"%' and ifShow in (0"+isadmin+") order by levwDate desc");
System.out.println(query);
System.out.println(query);
List lwList =null;
try {
lwList=query.list();
System.out.println("已经查找到了留言LIST");
} catch (HibernateException e) {
e.printStackTrace();
}
// Iterator iterator = lwList.iterator();
// while(iterator.hasNext()) {
// }
return lwList;
}
你把KeyWord打印出来看看是什么.
rs=stmt.executeQuery("select * from auditbook where docname Like '%借阅%'");编码绝对是没有,可就是查不出来,关注......
Object [] parameter={%+"郁闷"+%};
String hql="from table as t where t.name like ?";
this.getHibernateTemplate().find(hql,parameter);
Query query = session.createQuery("from LeaveWord l where l.ID = :id and l.levwTitle like :keyword ");
query.setParameter("id",gb.getIds());
query.setParameter("keyword","%"+params+"%");
改成这样试试
用这个
org.hibernate.hql.ast.QuerySyntaxError: unexpected AST node:
( [from com.xaoer.dowebsite.gBook.Beans.LeaveWord l where l.ID in (0,77,117) and l.levwTitle like :keyword order by levwDate desc],
为什么keyword参数没有替换掉呢?还请大家多多帮忙了