问题:通过Hibernate向MySQL写入中文后,通过Hibernate取回数据,在console中打印java对象显示正常。但在MySQL Query Browser中看到的是乱码,传给前端的Flex也是乱码。
原因:Hibernate的基础还是JDBC,所以一样需要设置characterEncoding!
解决方法:
在hibernate.cfg.xml中应该这样写
如果用hibernate.properties
#hibernate.connection.url jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8
ps:处理中文的话,characterEncoding用GBK一样可以。
但字节编码问题最好的解决方法还是统一使用UTF-8!!!
原因:Hibernate的基础还是JDBC,所以一样需要设置characterEncoding!
解决方法:
在hibernate.cfg.xml中应该这样写
<property name="connection.url">jdbc:mysql://localhost:3306/yidishui?useUnicode=true&characterEncoding=UTF-8</property>
#hibernate.connection.url jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8
ps:处理中文的话,characterEncoding用GBK一样可以。
但字节编码问题最好的解决方法还是统一使用UTF-8!!!
本文介绍了在使用Hibernate框架操作MySQL数据库时遇到的中文乱码问题及其解决方案。问题表现为通过Hibernate写入中文数据后,在MySQLQueryBrowser中显示为乱码。文章详细解释了解决此问题的方法,即在连接URL中加入特定参数以指定字符集编码。
1796

被折叠的 条评论
为什么被折叠?



