linux服务器,,,
select (case aa when 1 then '石家庄' when 2 then '北京' else '天津' end) as dd from tablejava调用执行的sql语句出来的是乱码,数据库执行的不是

解决方案 »

  1.   

    根据你的字符集
    set names 一下。http://blog.csdn.net/ACMAIN_CHM/archive/2009/05/12/4174186.aspx
    MySQL 中文显示乱码
      

  2.   

    又是字符集问题show variables like "%char%";
    检查你的server和client字符集是否一致
      

  3.   

    mysql> select (case productid when '135000000000000000704' then '中国区' when '0' then '亚洲区'  end ) as yewu,daytime,dinggou from bytjforday where productid='135000000000000000704' limit 0,10;
    +-----------+------------+---------+
    | yewu      | daytime    | dinggou |
    +-----------+------------+---------+
    | 中国区 | 2008-12-18 |       5 |
    | 中国区 | 2008-12-19 |       3 |
    | 中国区 | 2008-12-20 |      76 |
    | 中国区 | 2008-12-21 |      25 |
    | 中国区 | 2008-12-22 |      20 |
    | 中国区 | 2008-12-23 |      16 |
    | 中国区 | 2008-12-24 |     167 |
    | 中国区 | 2008-12-25 |       7 |
    | 中国区 | 2008-12-26 |      12 |
    | 中国区 | 2008-12-27 |      19 |
    +-----------+------------+---------+
    10 rows in set (0.00 sec)同样的sql语句
    只是在java中字符拼的
    String sql=“sqlstring”;
    daytime                yewu  dinggou
    2008-12-26 00:00:00 ???????   0  
    2008-12-26 01:00:00 ???????   0  
    2008-12-26 02:00:00 ???????   0  
    2008-12-26 03:00:00 ???????   0  
    2008-12-26 04:00:00 ???????   0 
    2008-12-26 05:00:00 ???????   0  
    2008-12-26 06:00:00 ???????   0 
    2008-12-26 07:00:00 ???????   0 
    2008-12-26 08:00:00 ???????   0我在mysql执行set names utf8,页面编码格式也是utf-8
    查询出来的还是问号
      

  4.   

    楼主好象没有去看一楼的贴子!在你的java中 set names utf8 !
      

  5.   

    我看了我在java代码中,每次调用sql语句执行之前都执行一遍set names utf8,但是还是不行啊。。
      

  6.   

    show create table bytjforday ;看一下。
      

  7.   

    弄好了发现set names utf8不太好用,
    我在网上查到修改配置文件,my.cnf来设置,不过没找到这个文件,后来发现我这个版本的mysql好像得从my-large.cnf cp过去改名,然后重新启动,现在问题解决。