Struts&MYSQL中文乱码..依旧有问题...

来源:百度知道 编辑:UC知道 时间:2024/06/04 10:15:40
所有JSP页面都是GB2312,加入过滤器,也设置为GB2312,MYSQL中数据库建立时database和表都加了default charset gb2312,my.ini中配置的也是GB2312,现在的效果是,在DOS界面直接insert into不是乱码,从JSP页面传值一直到Hibernate的DAO中session.save以前都不是乱码,只要一插进数据库就是了,实在不知道为什么还是有乱码...
我去,一试又好了,为什么呢,今天在两台机器上同样的配置都出现问题,现在我什么都没改一台机器上又好了

1:你建库的时候加上编码格式,这样就不用改my.ini了。。crate database db1 set character gb2312;
2:hibernate连接写法jdbc:mysql://localhost:3306/db1?useUnicode=true&characterEncoding=bk2312
试下。。应该可以的

INI 文件上 有2个地方 都改成 GB2312

[client]

port=3306

[mysql]

default-character-set=gb2312 -----这里

# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[mysqld]

# The TCP/IP Port the MySQL Server will listen on
port=3306

#Path to installation directory. All paths are usually resolved relative to this.
basedir="C:/Program Files/MySQL/MySQL Server 5.0/"

#Path to the database root
datadir="C:/Program Files/MySQL/MySQL Server 5.0/Data/"

# The defau