JAVA中文问题解决


1)编码问题
   return new String(oldString.getBytes("ISO-8859-1"), "GBK");
2)HQL查询中文问题
  HQL 写法: from obj where field1like '%中文%' 查询不出记录
  需要参数注入: from obj where field1like ?
                  query.setString(0,"%中文%")  注意不需要''



两外还可以这样解决:
hibernate3 在提交带有中文参数的sql语句时会有一个bug.无论你如何转型,提交的sql中,中文始终是乱码.解决方法是,在定义hibernate属性时.加上
<property name="hibernateProperties">
     <prop key="hibernate.query.factory_class">
     org.hibernate.hql.classic.ClassicQueryTranslatorFactory
    </prop>
 </props>

这是在spring中管理hibernate的时候的定义格式

原文地址:https://www.cnblogs.com/willpower/p/1177716.html