(1)在连接数据库的url后面加上:?useUnicode=true;characterEncoding=gbk;  
(2)在mysql的my.ini文件中加入default-character-set=gbk

解决方案 »

  1.   

    :?useUnicode=true;characterEncoding=gbk; 这句我试过了,不管用的。
    加gb2312也没有用。my.ini这个文件在什么地方?
    是在mysql中的目录下吗?我要上传到我购买的虚拟目录下,这样my.ini这个文件我可以更改吗?
      

  2.   

    UTF-8也不错
    好像不行吧。
    我刚试了一下,不好用,还是乱码。
      

  3.   

    (1)在连接数据库的url后面加上:?useUnicode=true;characterEncoding=gbk;  
    (2)在mysql的my.ini文件中加入default-character-set=gbk
    (3)看看你的数据库表的字集集,如果不是中文字符集修改一下。可能是utf8或是其它的。
    alert table ........
      

  4.   

    ALTER TABLE `库名`.`表名` CHARACTER SET gb2312;jdbc:mysql://192.168.1.90/库名?useUnicode=true&characterEncoding=gb2312
      

  5.   

    (3)看看你的数据库表的字集集,如果不是中文字符集修改一下。可能是utf8或是其它的。上面的数据库表的字符集用什么命令看,我没用过mysql.
    不知如何操作。
      

  6.   

    gb2312 或是gbk 前后要统一。
      

  7.   

    我要上传到购买的虚拟主机上面,
    我如何来解决我的mysql中文问题。是不是服务器端已经解决完了。
    还是需要自己来设置.
      

  8.   

    问题是先要找出是插入前就是乱码还是插入后变成乱码的,不要总是找数据库的原因,如果插入前是正常的,那么useUnicode=true;characterEncoding=gbk应该就不会有问题了,估计是插入前就是乱码,如果编个filter,
    public class SetCharEncode implements Filter
    {
        protected String encoding = null;
        protected FilterConfig filterConfig = null;
        protected boolean ignore = true;
        public void destroy() {
            this.encoding = null;
            this.filterConfig = null;
        }
        public void doFilter(ServletRequest request, ServletResponse response,
                             FilterChain chain)
            throws IOException, ServletException {
            String encoding = selectEncoding(request);
            request.setCharacterEncoding(encoding);
            response.setContentType("text/html;charset="+encoding);
            chain.doFilter(request, response);
        }
        public void init(FilterConfig filterConfig) throws ServletException {
            this.filterConfig = filterConfig;
            this.encoding = filterConfig.getInitParameter("encoding");
            String value = filterConfig.getInitParameter("ignore");
            if (value == null)
                this.ignore = true;
            else if (value.equalsIgnoreCase("true"))
                this.ignore = true;
            else if (value.equalsIgnoreCase("yes"))
                this.ignore = true;
            else
                this.ignore = false;
        }
        protected String selectEncoding(ServletRequest request)
        {
            return (this.encoding);
        }
    }
    在web.xml配置:
      <filter>
        <filter-name>setchar</filter-name>
        <filter-class>com.xdg.filter.SetCharEncode</filter-class>
        <init-param>
          <param-name>encoding</param-name>
          <param-value>UTF-8</param-value>
        </init-param>
      </filter>
      <filter-mapping>
        <filter-name>setchar</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>如果这样还有乱码,那就是奇迹了。这个方法我可是从来没有公布过的,而且最简单。算你走运。自己研究出来的。
      

  9.   

    呵呵
    谢谢楼上的了。我是在配置jive论坛出现的乱码问题。
    按你的方法回去试一下。
    看看是否能成功。加一个过滤器。
      

  10.   

    不好意思,有点错误,这样还是不好用,更正:
    public class SetCharEncode implements Filter
    {
        protected String encoding = null;
        protected FilterConfig filterConfig = null;
        protected boolean ignore = true;
        public void destroy() {
            this.encoding = null;
            this.filterConfig = null;
        }
        public void doFilter(ServletRequest request, ServletResponse response,
                             FilterChain chain)
            throws IOException, ServletException {
            String encoding = selectEncoding(request);
            request.setCharacterEncoding(encoding);
            response.setContentType("text/html;charset="+encoding.toLowerCase());//这个地方必须是小写,我也不知道为什么
            chain.doFilter(request, response);
        }
        public void init(FilterConfig filterConfig) throws ServletException {
            this.filterConfig = filterConfig;
            this.encoding = filterConfig.getInitParameter("encoding");
            String value = filterConfig.getInitParameter("ignore");
            if (value == null)
                this.ignore = true;
            else if (value.equalsIgnoreCase("true"))
                this.ignore = true;
            else if (value.equalsIgnoreCase("yes"))
                this.ignore = true;
            else
                this.ignore = false;
        }
        protected String selectEncoding(ServletRequest request)
        {
            return (this.encoding);
        }
    }
      

  11.   

    你的这个方法还是有问题。
    我试过来。
    必须要页面上要加上8859_1这个字符编码才可以通过。测试环境windows2000 server mysql4.1
      

  12.   

    但为什么加gbk或gb2312不行呢。
    只有加8859_1才可以。
      

  13.   

    我不用你的那个方法同样可以好用的。
    只需要把默认字符集设置为gbk,
    页面用8859_1即可通过测试。