使用Hibernate对MySql数据库插入中文数据时出现???乱码

先检查数据库的字符集,单击数据库中的表,点击 设计表,点击任意字段并查看字符集

一般是这样就可以的,没有问题。

然后呢我的解决办法是通过在hibernate.cfg.xml文件中的

<property name="hibernate.connection.url">
         <[CDATA[jdbc:mysql://localhost:3306/hibernateuseUnicode=true&characterEncoding=utf8]]>
</property>

url改为 <![CDATA[jdbc:mysql://localhost:3306/hibernate?useUnicode=true&characterEncoding=utf8]]> 

这样我的问题就解决了

做个笔记

发布了25 篇原创文章 · 获赞 8 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/FungLi_notLove/article/details/88585002