zoukankan      html  css  js  c++  java
  • Mysql数据库插入的中文字段值显示问号的问题解决

    最近我使用myeclipse连接mysql数据库查询表中的数据,表中字段值为中文的字段显示问号,查了很多资料将解决方法总结如下:

    步骤一:修改mysql数据库的配置文件my.ini或者my-default.ini

    [client]
     prot=3306
    [mysql]
     default-character-set=GBK
    [mysqld]
     default-character-set=utf8 
     collation-server=utf8_general_ci

    步骤二:创建数据库的时候指定数据库的编码格式,比如下面的例子展示的这样

    create database bbs DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
    
    use bbs;
    
    create table article 
    (
    id int primary key auto_increment,
    pid int,
    rootid int,
    title varchar(255),
    cont text,
    pdate datetime,
    isleaf int #1-not leaf 0-leaf
    );
    
    insert into article values (null, 0, 1, '蚂蚁大战大象', '蚂蚁大战大象', now(), 1);
    insert into article values (null, 1, 1, '大象被打趴下了', '大象被打趴下了',now(), 1);
    insert into article values (null, 2, 1, '蚂蚁也不好过','蚂蚁也不好过', now(), 0);
    insert into article values (null, 2, 1, '瞎说', '瞎说', now(), 1);
    insert into article values (null, 4, 1, '没有瞎说', '没有瞎说', now(), 0);
    insert into article values (null, 1, 1, '怎么可能', '怎么可能', now(), 1);
    insert into article values (null, 6, 1, '怎么没有可能', '怎么没有可能', now(), 0);
    insert into article values (null, 6, 1, '可能性是很大的', '可能性是很大的', now(), 0);
    insert into article values (null, 2, 1, '大象进医院了', '大象进医院了', now(), 1);
    insert into article values (null, 9, 1, '护士是蚂蚁', '护士是蚂蚁', now(), 0);

    步骤三:我的myeclipse的编码方式和创建的web项目的编码方式都是gbk;
    查询结果如下:

  • 相关阅读:
    钩子函数和回调函数
    Vue.js的坑
    数据库清空表中的数据
    chrome jsonView插件安装
    PostgreSQL数据的导出导入
    PostgreSQL9.6.2的WINDOWS下安装
    HEXO+Github,搭建属于自己的博客
    Vue.js 入门指南之“前传”(含sublime text 3 配置)
    win系统下nodejs安装及环境配置
    Vue.js学习网址
  • 原文地址:https://www.cnblogs.com/ysw-go/p/5919231.html
Copyright © 2011-2022 走看看