hibernate向mysql5插入中文,出现乱码

1 卸载mysql5,使用mysql5.5

2 hibernate.cfg.xml中hibernate.connection.url 设置如下,添加“?useUnicode=true&characterEncoding=utf8”

<property name="hibernate.connection.url">
		jdbc:mysql://localhost:3306/hibernate?useUnicode=true&characterEncoding=utf8
</property>

3 my.ini中设置default-character-set=gbk,只是为在dos中显示时使用gbk编码格式显示中文

[client]

port=3306

[mysql]

default-character-set=gbk

  

4 将myeclipse中编码格式设置为utf-8,包括workspace,spelling,context types对应的编码格式

5 使用Navicat for MySql,查询news_table,显示其中的数据已经不是乱码,即说明中文插入成功

posted @ 2016-03-30 22:32  CityGun  阅读(194)  评论(0编辑  收藏  举报