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

插入数据库一条数据:

 例如:

//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");

成功后:






搭上这一生命的列车,感受这生命的起点与终点
原文地址:https://www.cnblogs.com/s999/p/12266953.html