当前位置: 代码迷 >> Java Web开发 >> eclipse 中 jdbc 联接 mysql 插入数据中文乱码
  详细解决方案

eclipse 中 jdbc 联接 mysql 插入数据中文乱码

热度:3596   发布时间:2016-04-10 22:57:34.0
eclipse 中 jdbc 连接 mysql 插入数据中文乱码
那些个字符集我是一个也不明白,所以原理之类的,我是肯定不懂了
这是在我电脑上的三个命令的结果还有我随便 select * from student了一下,
第二个记录是我在eclipse中用 java jdbc插入的,在网上看了好多方法,不过都看不明白,每个人说的都有出入
我用了一个navicat,在新建连接的时候,在数据库的属性中字符是GBK,但是建立的那个用户连接就只能是utf8的,不能修改
我之后可能会搭建LAMP的环境做一点小网站练习,然后用JAVA SE + mysql 做一段时间的桌面应用
我应该怎么做?




mysql> use jdbctestthree;
Database changed
mysql> show create table student;
+---------+------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------+
| Table   | Create Table
                                                                                           |
+---------+------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------+
| student | CREATE TABLE `student` (
  `stId` int(11) NOT NULL,
  `stuName` char(20) NOT NULL DEFAULT '',
  `stuScore` decimal(5,2) NOT NULL DEFAULT '0.00',
  PRIMARY KEY (`stId`)
) ENGINE=InnoDB DEFAULT CHARSET=gbk |
+---------+------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)


mysql> show full columns from student;
+----------+--------------+----------------+------+-----+---------+-------+---------------------------------+---------+
| Field    | Type         | Collation      | Null | Key | Default | Extra | Privileges                      | Comment |
+----------+--------------+----------------+------+-----+---------+-------+---------------------------------+---------+
| stId     | int(11)      | NULL           | NO   | PRI | NULL    |       | select,insert,update,references |         |
| stuName  | char(20)     | gbk_chinese_ci | NO   |     |         |       | select,insert,update,references |         |
| stuScore | decimal(5,2) | NULL           | NO   |     | 0.00    |       | select,insert,update,references |         |
+----------+--------------+----------------+------+-----+---------+-------+---------------------------------+---------+
3 rows in set (0.03 sec)

mysql> show variables like 'char%';
+--------------------------+---------------------------------------------------------+
| Variable_name            | Value                                                   |
+--------------------------+---------------------------------------------------------+
| character_set_client     | gbk                                                     |
| character_set_connection | gbk                                                     |
| character_set_database   | gbk                                                     |
  相关解决方案