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;
}高手请帮我看看这个方法,为什么能够查询到字母和数字,却查询不到中文的呢?谢谢了

解决方案 »

  1.   

    代码格式真乱,看得头晕.
    检查下你的KeyWord里的中文正常吗?是不是乱码?是的话转一下码就OK啦.
      

  2.   

    不是乱码。那我在帖一次
    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;
    }
      

  3.   

    不会吧,不是乱码应该可以查出来的吧!!
    你把KeyWord打印出来看看是什么.
      

  4.   

    我也遇到了这个问题,where 条件里有中文查不出来,后来我用JDBC写了个查询语句,就能够查出来
    rs=stmt.executeQuery("select * from auditbook  where docname Like '%借阅%'");编码绝对是没有,可就是查不出来,关注......
      

  5.   

    跟半角全角没多大关系吧
    Object [] parameter={%+"郁闷"+%};
    String hql="from table as t where t.name like ?";
    this.getHibernateTemplate().find(hql,parameter);
      

  6.   

    文字应该没有全角和半角之分吧,符号才有
    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+"%");
    改成这样试试
      

  7.   

    this.getHibernateTemplate().find(" from table as t where t.name like ?",new Object[] {"不郁闷"}, new Type[] {Hibernate.STRING});
    用这个
      

  8.   

    嗯,反正就这个意思,不要直接并HQL,这样会有BUG的
      

  9.   

    这样是可以的:  将关键字转成iso8859-1,,再去查.. new String("关键字".getBytes("GBK"),"iso8859_1");
      

  10.   

    不知道怎么回事,现在报错了:
    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参数没有替换掉呢?还请大家多多帮忙了
      

  11.   

    to : sundeveloper(51TTUP),不可以呀,我用的是UTF-8的编码
      

  12.   

    终于解决了,就向你们所说的,不能并接HQL,谢谢你们了,给分