解决Hibernate向MySQL数据库插入中文乱码问题

时间:2021-07-19 07:09:23

在hibernate中将数据插入到mysql中时,遇到中文乱码的问题!

解决Hibernate向MySQL数据库插入中文乱码问题

1.检查数据库编码是否为UTF-8编码

2.在hibernate的配置文件hibernate.cfg.xml中修改连接数据库的字符串:

<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate_first/property>

在连接数据库的后面加上如下字符串?useUnicode=true&amp;characterEncoding=UTF8

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


解决Hibernate向MySQL数据库插入中文乱码问题