struts+hibernate+mysql中文乱码解决
一.首先从根源开始,我的mysql是5.0版本,设置mysql字符集为通用语言
二.my.ini文件里 设成
[mysql]
default-character-set=gbk
三.建一个MyRequestProcessor类:
public class MyRequestProcessor extends RequestProcessor {
protected boolean processPreprocess(HttpServletRequest request, HttpServletResponse response) {
try {
request.setCharacterEncoding("GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return false;
}
return true;
}
}
四.hibernate.cfg.xml里连接数据库为
<property name="connection.username">root</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/poor
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="myeclipse.connection.profile">mysql</property>
<property name="connection.password">ok</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
ok.....插入和查询中文乱码解决,mysql控制台显示的也是中文,但是如果要是用mysql数据库控制台插件,中文显示的却是乱码,还没来及解决,希望能给大家带来帮助,如不明白的地方请留言,