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

xiaoxiao2021-02-27  122

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

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

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

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

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

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

转载请注明原文地址: https://www.6miu.com/read-14265.html

最新回复(0)