hibernate中文乱码问题

在学习hibernate的过程中,发现在往mysql数据库中插入数据的时候会报错。

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

这是在hibernate配置文件中设置的编码格式,经过查找问题原因,发现是数据库的默认编码格式为latin。

所以需要更改数据库的默认编码格式。

hibernate中文乱码问题

更改test数据库的默认编码格式

hibernate中文乱码问题

然后插入就完全没有问题了,也可以正常显示了。

hibernate中文乱码问题

hibernate中文乱码问题

顺便说一句查看表的默认编码格式和修改其编码格式

和修改数据库的差不多。

查看编码格式show create table student  G;

改变编码格式alter table student character set utf8;