SSH 数据库乱码问题

2016-10-20  本文已影响0人  枝头残月野狼嚎嗷嗷呜

最近玩的项目里面用的H2,Hibernate的import.sql里面插入了一条中文的数据,结果是乱码,搞了半天没有解决。网上关于H2连接相关的资料比较少,关于解决mysql乱码问题的文章比较多,于是把数据库切换到了mysql,但问题依然存在。
并且已经确定了mysql数据库的encoding、import.sql的encoding都是utf8。
包括hibernate配置文件中关于Mysql连接的配置

        <property name="hibernate.connection.CharSet">utf-8</property>
        <property name="hibernate.connection.characterEncoding">utf-8</property>
        <property name="hibernate.connection.useUnicode">true</property>

经过一番调查,终于解决了。

解决办法

修改完以后,再用hibernate导入import.sql,就不乱码了。
即使去掉这些配置也没关系

        <property name="hibernate.connection.CharSet">utf-8</property>
        <property name="hibernate.connection.characterEncoding">utf-8</property>
        <property name="hibernate.connection.useUnicode">true</property>

再切换回H2数据库,同样一切正常。


此次问题得以解决,得力于这篇文章

hibernate hbm2ddl.import_files 中文乱码问题

上一篇 下一篇

猜你喜欢

热点阅读