插入数据库一条数据,出现乱码问题。

插入数据库一条数据:

 例如:

//2.建立连接 参数 地址 用户 ,密码
Connection con= DriverManager.getConnection(url:"jdbc:mysql://localhost:3306/db2020", user:"root", password:"123456");
//3.准备sql
String sql="INSERT into cat VALUES(NULL,'狸猫',4)";


数据库出现:


解决办法:修改
Connection con= DriverManager.getConnection("jdbc:mysql://localhost:3306/db2020?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&allowMultiQueries=true&serverTimezone=Asia/Shanghai", "root", "123456");

成功后:






posted @ 2020-02-05 22:13  星月星辰  阅读(217)  评论(0编辑  收藏  举报