环境介绍:
MySQL版本:5.6 .51
Java版本:JDK11
操作系统:Windows10 2004
JDBC版本:mysql- connector- java- 8.0 .22
注册驱动时:
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'.
The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
数据库驱动 com.mysql.jdbc.Driver 已经被弃用了,应当使用新的驱动 com.mysql.cj.jdbc.Driver
解决方案:
更改代码:Class. forName ( "com.mysql.jdbc.Driver" ) ;
修改为:Class. forName ( "com.mysql.cj.jdbc.Driver" ) ;
连接 jdbc 时:
The server time zone value '�й���ʱ��' is unrecognized or represents more than one time zone.
使用了 Mysql Connector/J 6.x 以上的版本,然后就报了时区的错误。加入参数 serverTimezone=UTC 就好了。
解决方案:
更改url:String url = "jdbc:mysql://localhost:3306/test" ;
修改为:String url = "jdbc:mysql://localhost:3306/test?serverTimezone=UTC"
执行 sql 语句时:
执行sql语句:"update dept set dname = '张三', loc = '北京' where deptno = 20";修改数据发现乱码。
解决方案:
更改url:String url = "jdbc:mysql://localhost:3306/test?serverTimezone=UTC"
修改为:String url = "jdbc:mysql://localhost:3306/test?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF-8"