hibernate连接mysql的编码设置

来源:互联网 发布:江苏计算机二级vb真题 编辑:程序博客网 时间:2024/06/18 17:45

问题:最近项目开发中,碰到了中文乱码问题。Mysql已设置为UTF-8,内存中的内容是正常,通过hibernate保存到Mysql数据库中就是乱码。

 

解决:

设置Hibernate的编码,两种方式:

1.hibernate.cfg.xml或applicationContenxt.xml文件中设置,如下:

< property  name ="url" > jdbc:mysql://localhost:3306/test?useUnicode=true &amp;characterEncoding=UTF-8 </ property >

注意:在xml中,用&amp;代替&, 否则启动检测xml配置文件格式报错。

2. 通过hibernate.properties设置

#hibernate.connection.url jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8


原文地址:http://javafansmagic.iteye.com/blog/1133886

0 0
原创粉丝点击