1.要设置mysql数据库的utf-8格式

(1)找到mysql的my.ini增加如下内容

mysql存储中文设置

(2)重启数据库服务, 检查一下

mysql存储中文设置

mysql存储中文设置

 

2. 创建表的时候引擎默认字符集设置成utf-8

use jdbcstudy;

CREATE TABLE `testclob` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `resume` text,

  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

这个字符集默认是latin 不改为utf8存储时会发生以下错误

java.sql.SQLException: Incorrect string value: '\xEF\xBB\xBFliy...' for column 'resume' at row 1

3. jdbc的数据库url加上编码

driver=com.mysql.jdbc.Driver

url=jdbc:mysql://localhost:3306/jdbcstudy?useUnicode=true&characterEncoding=utf8

username=root

password=

 

然后就可以正常存储中文了

相关文章:

  • 2021-05-24
  • 2021-12-01
  • 2022-01-04
  • 2022-12-23
  • 2021-09-04
  • 2021-07-05
  • 2022-12-23
猜你喜欢
  • 2022-01-10
  • 2021-05-30
  • 2021-11-24
  • 2022-02-08
  • 2021-10-11
  • 2021-04-29
  • 2022-12-23
相关资源
相似解决方案