`
javafansmagic
  • 浏览: 34638 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

hibernate连接mysql的编码设置

阅读更多

问题:最近项目开发中,碰到了中文乱码问题。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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics