java程序向MySql中插入数据报错:alter table score change score score varchar(50) character utf8;

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_17505335/article/details/79226732

jdbc配置:

driverName=com.mysql.jdbc.Driver
url=jdbc\:mysql\://localhost\:3306/mobile_scm?useUnicode=true&characterEncoding=UTF-8
username=xxx
password=xxx

报错:
这里写图片描述

解决方法:
1.查看表的编码

show create table sys_menu;
+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table    | Create Table                                                                                                                                                                                                                                                                                                                                                                                                           |
+----------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| sys_menu | CREATE TABLE `sys_menu` (
  `menuid` varchar(255) CHARACTER SET latin1 NOT NULL,
  `menuname` varchar(255) DEFAULT NULL,
  `parentid` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
  `actionid` varchar(255) DEFAULT NULL,
  `type` tinyint(4) DEFAULT NULL,
  `sortorder` tinyint(4) DEFAULT NULL,
  `remark` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
  PRIMARY KEY (`menuid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |

可以看到表的编码是utf8,但是字段‘remark’的编码是latin1,修改字段remark编码

mysql> alter table sys_menu change `remark` `remark` varchar(255) character set utf8;

Query OK, 3 rows affected
Records: 3  Duplicates: 0  Warnings: 0

mysql> show create table sys_menu;
+----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table    | Create Table                                                                                                                                                                                                                                                                                                                                                                                      |
+----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| sys_menu | CREATE TABLE `sys_menu` (
  `menuid` varchar(255) CHARACTER SET latin1 NOT NULL,
  `menuname` varchar(255) DEFAULT NULL,
  `parentid` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
  `actionid` varchar(255) DEFAULT NULL,
  `type` tinyint(4) DEFAULT NULL,
  `sortorder` tinyint(4) DEFAULT NULL,
  `remark` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`menuid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set

修改成功后,再执行程序发现问题成功解决!!

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页