zoukankan      html  css  js  c++  java
  • JDBC插入中文出现乱码问题

    使用命令行插入中文的时候出现:

    ERROR 1366: 1366: Incorrect string value: 'xE5xA5xB3' for column

    这是因为创建表的时候未指定编码集,需使用utf-8

    例如:

    create table student(id int(8) not null auto_increment, name varchar(32) default null, grade_id int(8) not null, picture varchar(128) default null, sex char(4) default null, primary key (id))character set=utf8;

    使用JDBC插入中文数据的时候显示未“???”或乱码,是因为JDBC的打开连接没有指定字符集。例:

    String url = "jdbc:mysql://localhost:3306/lab_system?useSSL=true&characterEncoding=utf-8";

    测试结果:

    +----+-----------+----------+---------+------+
    | id | name      | grade_id | picture | sex  |
    +----+-----------+----------+---------+------+
    |  1 | ???       |       10 |         | ?    |
    |  2 | ???       |       10 |         | ?    |
    |  3 | 胀死啊    |       10 |         | 男   |
    +----+-----------+----------+---------+------+
  • 相关阅读:
    将Excel文件.xls导入SQL Server 2005
    linux mount命令
    python write file
    vim visual模式 复制
    chef简介
    录音整理文字工具otranscribe简介
    ftp put get 的使用方法
    yum lock 解决方法
    phalcon builder get raw sql
    centos7安装VirtualBox
  • 原文地址:https://www.cnblogs.com/meilj/p/9235420.html
Copyright © 2011-2022 走看看