我使用的是Mysql数据库,数据库的字符集使用UTF-8。
在数据库中显示为中文字段的信息,用otl_stream流输出之后是“问号”。
例如:在表中有一个字段名为subject对应的字段内容是:主题,就是主题,subject from。使用m_cOtlStream >> m_cTmp;输出到m_cTmp变量中,结果变成了:????????,subject from。就是说中文字符变成了问号,英文输入下输出的都是正常的,请问如何解决之?

解决方案 »

  1.   

    字符集问题,贴下你的show variables like 'character_set%';
    输出的m_cTmp变量中变量指定下utf8 试试
      

  2.   

    检查一下你的字符集设置。 可以参考下贴中的检查方法。
    http://blog.csdn.net/ACMAIN_CHM/archive/2009/05/12/4174186.aspx
    MySQL 中文显示乱码
      

  3.   


    mysql> show variables like 'character_set%';
    +--------------------------+----------------------------------------------------
    -----+
    | Variable_name            | Value
         |
    +--------------------------+----------------------------------------------------
    -----+
    | character_set_client     | latin1
         |
    | character_set_connection | latin1
         |
    | character_set_database   | latin1
         |
    | character_set_filesystem | binary
         |
    | character_set_results    | latin1
         |
    | character_set_server     | latin1
         |
    | character_set_system     | utf8
         |
    | character_sets_dir       | D:\Program Files\MySQL\MySQL Server 5.0\share\chars
    ets\ |
    +--------------------------+----------------------------------------------------
    -----+
    8 rows in set (0.02 sec)mysql>
      

  4.   

    要怎么设置呀?我已经贴出来了。以前没有用过mysql
      

  5.   

    set names utf8 再导出;还有就是你的变量声明出来也设置成utf8;试试,
      

  6.   

    我都设置成UTF8还是不行,输出还是乱码,而且重启mysql服务之后,character_set又变成原先的了。
      

  7.   

    怎么设置啊?变量声明出来怎么设置成utf8?
      

  8.   


    declare m_cTmp varchar(100) character set utf8; 
      

  9.   

    数据库中现在显示的中文中正常的,只是用otl_stream流写到界面或者输出之后就变乱码了。
    你说的是什么意思?m_cTmp我是在VC中定义的char[]变量。
      

  10.   

    看看 ACMAIN_CHM 老大给的地址 绝对有帮助。顺便告诉你一声。除了设置数据库 最好也罢变量也设置了类型
      

  11.   

    字符集问题,不统一
    set names latin1
    试试
    在统一字符集的下重新插入记录
      

  12.   

    在你的程序里set names 'latin1',再取结果看看。
      

  13.   

    Enter password: ******
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 4 to server version: 5.0.22-community-ntType 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mailreceiver       |
    | mysql              |
    | test               |
    +--------------------+
    4 rows in set (0.00 sec)mysql> use test;
    Database changed
    mysql> show tables;
    Empty set (0.00 sec)mysql> use mailreceiver;
    Database changed
    mysql> show tables;
    +------------------------+
    | Tables_in_mailreceiver |
    +------------------------+
    | mailaccount            |
    | mailinfo               |
    | servertable            |
    | test_tab               |
    +------------------------+
    4 rows in set (0.00 sec)mysql> show create table mailinfo;
    +----------+--------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    -------------------------------------------------------------------------+
    | Table    | Create Table
                                                                             |
    +----------+--------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    -------------------------------------------------------------------------+
    | mailinfo | CREATE TABLE `mailinfo` (
      `Id` int(11) NOT NULL auto_increment,
      `Subject` varchar(128) default '',
      `From` varchar(64) default NULL,
      `To` varchar(64) default NULL,
      `DateTime` datetime default '1901-01-01 01:01:01',
      `MessageId` varchar(128) default NULL,
      `AttachName` varchar(512) default NULL,
      `MailPath` varchar(255) default NULL,
      `HasRead` bit(1) default '\0' COMMENT '是否阅读',
      PRIMARY KEY  (`Id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=gb2312 |
    +----------+--------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --------------------------------------------------------------------------------
    -------------------------------------------------------------------------+
    1 row in set (0.05 sec)mysql> show variables like 'character_set_%';
    +--------------------------+----------------------------------------------------
    -----+
    | Variable_name            | Value
         |
    +--------------------------+----------------------------------------------------
    -----+
    | character_set_client     | gb2312
         |
    | character_set_connection | gb2312
         |
    | character_set_database   | gb2312
         |
    | character_set_filesystem | binary
         |
    | character_set_results    | gb2312
         |
    | character_set_server     | gb2312
         |
    | character_set_system     | utf8
         |
    | character_sets_dir       | D:\Program Files\MySQL\MySQL Server 5.0\share\chars
    ets\ |
    +--------------------------+----------------------------------------------------
    -----+
    8 rows in set (0.00 sec)mysql> show full columns from mailinfo;
    +------------+--------------+-------------------+------+-----+------------------
    ---+----------------+---------------------------------+----------+
    | Field      | Type         | Collation         | Null | Key | Default
       | Extra          | Privileges                      | Comment  |
    +------------+--------------+-------------------+------+-----+------------------
    ---+----------------+---------------------------------+----------+
    | Id         | int(11)      | NULL              | NO   | PRI | NULL
       | auto_increment | select,insert,update,references |          |
    | Subject    | varchar(128) | gb2312_chinese_ci | YES  |     | NULL
       |                | select,insert,update,references |          |
    | From       | varchar(64)  | gb2312_chinese_ci | YES  |     | NULL
       |                | select,insert,update,references |          |
    | To         | varchar(64)  | gb2312_chinese_ci | YES  |     | NULL
       |                | select,insert,update,references |          |
    | DateTime   | datetime     | NULL              | YES  |     | 1901-01-01 01:01:
    01 |                | select,insert,update,references |          |
    | MessageId  | varchar(128) | gb2312_chinese_ci | YES  |     | NULL
       |                | select,insert,update,references |          |
    | AttachName | varchar(512) | gb2312_chinese_ci | YES  |     | NULL
       |                | select,insert,update,references |          |
    | MailPath   | varchar(255) | gb2312_chinese_ci | YES  |     | NULL
       |                | select,insert,update,references |          |
    | HasRead    | bit(1)       | NULL              | YES  |     |
       |                | select,insert,update,references | 是否阅读 |
    +------------+--------------+-------------------+------+-----+------------------
    ---+----------------+---------------------------------+----------+
    9 rows in set (0.03 sec)mysql>
    ---------------------
    老大们,再看一下。就是mailinfo里的subject中有中文,在到界面显示时都变成“问号”了。以上是检查的所有字符集设置,有什么问题没有??谢谢。
      

  14.   

    我试图去改character_set_system 的字符设置也是gb2312,看能否把问题解决了。但是提示我说不能修改。不知道这个是不是我安装mysql是选择的默认字符集,不可以修改吗?
      

  15.   

    ) ENGINE=InnoDB DEFAULT CHARSET=gb2312 你的表中字符集是GB2312 不是UTF。
      

  16.   

    set names 'GB2312'
    试试
      

  17.   

    这个随你自己决定。
    如果要改成UTF8的话,你需要把数据先导出,然后改表为UTF8后再导入。
      

  18.   


    我按老大帖子说的重做了一个表,设置如下:
    Enter password: ******
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 1 to server version: 5.0.22-community-ntType 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql> show variables like 'char%';
    +--------------------------+----------------------------------------------------
    -----+
    | Variable_name            | Value
         |
    +--------------------------+----------------------------------------------------
    -----+
    | character_set_client     | gbk
         |
    | character_set_connection | gbk
         |
    | character_set_database   | gbk
         |
    | character_set_filesystem | binary
         |
    | character_set_results    | gbk
         |
    | character_set_server     | gbk
         |
    | character_set_system     | utf8
         |
    | character_sets_dir       | D:\Program Files\MySQL\MySQL Server 5.0\share\chars
    ets\ |
    +--------------------------+----------------------------------------------------
    -----+
    8 rows in set (0.00 sec)mysql> select * from test;
    ERROR 1046 (3D000): No database selected
    mysql> use mailreceiver;
    Database changed
    mysql> select * from test;
    +----+---------------------------------------+
    | Id | testchinese                           |
    +----+---------------------------------------+
    |  1 | so sosososoos右在夺得地在寺。so yuman |
    +----+---------------------------------------+
    1 row in set (0.00 sec)mysql> show full columns from test;
    +-------------+--------------+----------------+------+-----+---------+----------
    ------+---------------------------------+---------+
    | Field       | Type         | Collation      | Null | Key | Default | Extra
          | Privileges                      | Comment |
    +-------------+--------------+----------------+------+-----+---------+----------
    ------+---------------------------------+---------+
    | Id          | int(11)      | NULL           | NO   | PRI | NULL    | auto_incr
    ement | select,insert,update,references |         |
    | testchinese | varchar(255) | gbk_chinese_ci | YES  |     | NULL    |
          | select,insert,update,references |         |
    +-------------+--------------+----------------+------+-----+---------+----------
    ------+---------------------------------+---------+
    2 rows in set (0.00 sec)mysql> show create table test;
    +-------+-----------------------------------------------------------------------
    --------------------------------------------------------------------------------
    -------------+
    | Table | Create Table             |
    +-------+-----------------------------------------------------------------------
    --------------------------------------------------------------------------------
    -------------+
    | test  | CREATE TABLE `test` (
      `Id` int(11) NOT NULL auto_increment,
      `testchinese` varchar(255) default NULL,
      PRIMARY KEY  (`Id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=gbk |
    +-------+-----------------------------------------------------------------------
    --------------------------------------------------------------------------------
    -------------+
    1 row in set (0.00 sec)mysql>-------------------------------
    然后我在VC中用如下语句去访问
    const char* szTestSql = "select * from test";
    if (!m_otldb.Open(szTestSql))
    {
    return;
    }
    while (!m_otldb.Eof())
    {
    std::string strOut = m_otldb.FieldbyName("testchinese").c_str();
    }得到的strOut的值是:so sosososoos????????so yuman
    哪里错了? 为什么得到的中文变问号了。。
      

  19.   

    谁能告诉一下,MS SQL Server的数据库是用的什么字符设置?在哪里看。我用上述一样的库表结构,一样的程序,使用MS SQL Server数据库时,显示中文是没问题的。
      

  20.   

    我还做了如下测试:
    Enter password: ******
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 10 to server version: 5.0.22-community-ntType 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql> show variables like 'character_set_%';
    +--------------------------+----------------------------------------------------
    -----+
    | Variable_name            | Value
         |
    +--------------------------+----------------------------------------------------
    -----+
    | character_set_client     | utf8
         |
    | character_set_connection | utf8
         |
    | character_set_database   | utf8
         |
    | character_set_filesystem | binary
         |
    | character_set_results    | utf8
         |
    | character_set_server     | utf8
         |
    | character_set_system     | utf8
         |
    | character_sets_dir       | D:\Program Files\MySQL\MySQL Server 5.0\share\chars
    ets\ |
    +--------------------------+----------------------------------------------------
    -----+
    8 rows in set (0.00 sec)mysql> select * from test;
    ERROR 1046 (3D000): No database selected
    mysql> use mailreceiver;
    Database changed
    mysql> select * from test;
    +----+-----------------------------------------------+
    | Id | testchinese                                   |
    +----+-----------------------------------------------+
    |  1 | so sosososoos鍙冲湪澶哄緱鍦板湪瀵恒€俿o yuman         |
    +----+-----------------------------------------------+
    1 row in set (0.00 sec)mysql> set names 'gbk';
    Query OK, 0 rows affected (0.00 sec)mysql> select * from test;
    +----+---------------------------------------+
    | Id | testchinese                           |
    +----+---------------------------------------+
    |  1 | so sosososoos右在夺得地在寺。so yuman              |
    +----+---------------------------------------+
    1 row in set (0.00 sec)mysql> set names 'gb2312';
    Query OK, 0 rows affected (0.00 sec)mysql> select * from test;
    +----+---------------------------------------+
    | Id | testchinese                           |
    +----+---------------------------------------+
    |  1 | so sosososoos右在夺得地在寺。so yuman              |
    +----+---------------------------------------+
    1 row in set (0.00 sec)mysql> set names 'latin1';
    Query OK, 0 rows affected (0.00 sec)mysql> select * from test;
    +----+-------------------------------+
    | Id | testchinese                   |
    +----+-------------------------------+
    |  1 | so sosososoos????????so yuman |
    +----+-------------------------------+
    1 row in set (0.00 sec)mysql> set names 'gbk';
    Query OK, 0 rows affected (0.00 sec)mysql> select * from test;
    +----+---------------------------------------+
    | Id | testchinese                           |
    +----+---------------------------------------+
    |  1 | so sosososoos右在夺得地在寺。so yuman              |
    +----+---------------------------------------+
    1 row in set (0.00 sec)mysql>
    当设置为'latin1'时查询出来的结果和我看到的结果一样的,问号。什么情况?
      

  21.   

    就是你字符集不一样,导致乱码.你set names gbk,gb2312, 都可以正常显示中文;
    你在程序里set names  gb2312 取结果试试