又碰到Hibernate3.1插入中文乱码的问题了,好在瞎掰几下弄好了。
记下来,没准下次还遇上。
我的开发环境:Hibernate3.1+mysql5.0+jdk5.0
1、先检查my.ini,修改default-character-set=utf-8(urf-8大小写均可)
2、检查hibernate.cfg.xml中的connection.url属性。应该为:
<property name="connection.url">
jdbc:mysql://localhost:3306/izou?useUnicode=true&characterEncoding=UTF-8
</property>
3、写段程序试试:
Session session = HibernateSessionFactory.getSession();
Transaction tx = session.beginTransaction();
UserDAO udao = new UserDAO();
String name = "中国人";
User user = new User();
user.setUsrName(name);
udao.save(user);
tx.commit();
HibernateSessionFactory.closeSession();
本文介绍了解决Hibernate3.1在MySQL数据库中插入中文时出现乱码的方法,包括配置my.ini文件和hibernate.cfg.xml文件的具体步骤。
1421

被折叠的 条评论
为什么被折叠?



