Hql传中文参数出现乱码(同sql传中…
2014-06-05 16:04
148 查看
可以在spring配置文件中配置: [html] view
plaincopyprint?<</SPAN>property name="hibernateProperties"> <</SPAN>props> <</SPAN>prop key="hibernate.dialect">${hibernate.dialect}</</SPAN>prop> <</SPAN>prop key="hibernate.show_sql">${hibernate.show_sql}</</SPAN>prop> <</SPAN>prop key="connection.autocommit">false</</SPAN>prop> org.hibernate.hql.classic.ClassicQueryTranslatorFactory可以在hibernate.cfg.xml中配置: [html] view
plaincopyprint?<</SPAN>property name="hibernate.query.factory_class"> org.hibernate.hql.classic.ClassicQueryTranslatorFactory </</SPAN>property> 或者在写HQL的时候不吧中文参数拼凑进去,用query的setXxx。 setProperties()方法 个人觉得这个跟ORM技术的ibatis中的SQLMAP有些许相似。它是用setProperties()方法。如:String hql
= " from Customer user where 1=1 and userr.mc like :sna
" ;
Customer cus
= new Customer();
cus.setMc(
" 惠止南国 "
);
Session session
= getHibernateTemplate().getSessionFactory().openSession();
Transaction tx
= session.beginTransaction();
List returnList
= session.createQuery(sql).setProperties(cus).list();
tx.commit();
session.close();
plaincopyprint?<</SPAN>property name="hibernateProperties"> <</SPAN>props> <</SPAN>prop key="hibernate.dialect">${hibernate.dialect}</</SPAN>prop> <</SPAN>prop key="hibernate.show_sql">${hibernate.show_sql}</</SPAN>prop> <</SPAN>prop key="connection.autocommit">false</</SPAN>prop> org.hibernate.hql.classic.ClassicQueryTranslatorFactory可以在hibernate.cfg.xml中配置: [html] view
plaincopyprint?<</SPAN>property name="hibernate.query.factory_class"> org.hibernate.hql.classic.ClassicQueryTranslatorFactory </</SPAN>property> 或者在写HQL的时候不吧中文参数拼凑进去,用query的setXxx。 setProperties()方法 个人觉得这个跟ORM技术的ibatis中的SQLMAP有些许相似。它是用setProperties()方法。如:String hql
= " from Customer user where 1=1 and userr.mc like :sna
" ;
Customer cus
= new Customer();
cus.setMc(
" 惠止南国 "
);
Session session
= getHibernateTemplate().getSessionFactory().openSession();
Transaction tx
= session.beginTransaction();
List returnList
= session.createQuery(sql).setProperties(cus).list();
tx.commit();
session.close();
相关文章推荐
- hql/sql传中文参数出现乱码
- mysql5导入sql文件,中文出现乱码的解决办法
- hibernate的sql语句中传中文参数乱码问题
- JAVASCRIPT用Url传递参数出现中文乱码的解决方法
- 解决ASP.NET带中文参数出现乱码的问题
- 静态页面html之间传递中文参数出现乱码问题的解决方案
- prototype.js的使用: 中文参数出现乱码
- Jsp中通过get方法传递参数为中文时出现乱码如何解决?
- 在SQL Server 2005(2008)中用T-SQL插入中文数据时出现的问号或乱码的解决方案
- 彻底解决get显示提交时,参数中包含中文时出现乱码的问题
- hibernate3中hql中文参数乱码
- hibernate3中hql中文参数乱码
- HQL中文参数乱码问题
- PL/SQL导入sql脚本出现中文乱码的解决方法
- hibernate之HQL传中文参数乱码 解决办法
- 关于使用showModalDialog传递参数出现中文乱码问题
- 在SQL 2005中用T-SQL插入中文数据时出现的问号或乱码的解决方案!!!!
- 导入sql脚本时中文出现乱码的奇怪问题
- ASP.NET中url传递中文的解决方案,传递参数为汉字时出现乱码等问题
- 在SQL 2005中用T-SQL插入中文数据时出现的问号或乱码的解决方案