SSH MySql乱码解决方案
2013-11-21 14:05
357 查看
环境:Hibernate 3.2 + MySQL5.0(MySQL的编码已设置为utf8)
问题:通过Hibernate向MySQL写入中文后,通过Hibernate取回数据,在console中打印java对象显示正常。但在MySQL
Query Browser中看到的是乱码,传给前端的Flex也是乱码。
原因:Hibernate的基础还是JDBC,所以一样需要设置characterEncoding!
解决方法:
在hibernate.cfg.xml中应该这样写
<property name="connection.url">jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8</property>
如果用hibernate.properties
#hibernate.connection.urljdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8
ps:处理中文的话,characterEncoding用GBK一样可以。
但字节编码问题最好的解决方法还是统一使用UTF-8
-----
我的项目是:
<property name="connection.url">jdbc:mysql://localhost:3306/myeshop?useUnicode=true&characterEncoding=UTF-8</property>
2.同样在spring里的applicationContext.xml里的数据库连接也要修改:
<property name="url"value="jdbc:mysql://localhost:3306/myeshop?useUnicode=true&characterEncoding=UTF-8"></property>
3.在Web.xml中配置encodingFilter过滤器,在web.xml中加入下面代码
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
4.mysql库表要都以UTF-8编码建表。
5.jsp页面编码形式:
<%@ page language="java"import="java.util.*" pageEncoding="UTF-8"%>
相关文章推荐
- 【SSH网上商城】——MySQL存入数据库乱码问题及解决方案
- MySQL字符集中文乱码终极解决方案和mysql查询中文问题解决方法[转贴]
- mysql中的中文乱码解决方案, 全部是 这篇文章的内容: https://www.52jbj.com/jbdq/18755.html
- MySQL数据库基础-MySQL字符集乱码问题最终解决方案
- Mysql中文乱码问题完美解决方案
- Mysql与JSP网页中文乱码问题的解决方案
- MySql中文乱码问题以及Incorrect string value: '\xF0\x9F...' 问题的解决方案
- JavaEE应用中MySQL中文乱码完全解决方案
- JSP+ MySQL中文乱码问题post提交乱码解决方案
- MySql与SSH结合时产生的中文乱码问题
- Navicat 8 for MySQL 中文乱码解决方案
- python3 连接 mysql 遇到乱码问题解决方案
- Prepared Statement在mysql下中文乱码解决方案
- Mysql中文乱码问题完美解决方案
- mysql写入数据库后,数据出现乱码问题的解决方案
- delphi+mysql乱码问题解决方案
- Mysql中文乱码问题完美解决方案
- mysql导入utf8文件出现乱码解决方案
- Mysql 的字符编码机制、中文乱码问题及解决方案
- MYSQL 命令行显示乱码 解决方案