Mysql中文乱码解决

1.将Eclipse设为utf-8

Window--Preferences--General--Workspace,Text file encoding 选项中默认的Default(GBK)选项更改为Other,并将值设为utf-8

或者在项目上右键 Properties-Resource 将Text file encoding改为utf-8

2.修改mysql的编码方式

修改my.init中的编码方式为gbk。找到my.init文件修改:

default-character-set=gbk

3.hibernate.cfg.xml文件中写入编码方式

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

这里一定要是UTF-8之前设置为gbk,插入没有问题如果查询的时候有中文就会出现问题。

原文地址:https://www.cnblogs.com/doublesong/p/2707959.html