MySQL驱动jar包传送门
我用的是8.0.1的jar包,当时是报了两个错。
1.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.
这个报错很长,但就是想告诉你一件事,驱动换了!
(通过红色的字可以看出)
//这是原来的写法
Class.forName("com.mysql.jdbc.Driver");
//这是8.0以上的写法
Class.forName("com.mysql.cj.jdbc.Driver");
不过到了5的版本以上就可以省略这句了。
2.The server time zone value ‘�й���ʱ��’ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
emmmm。。。。这个报错更长了,但其实也是写法上出现了问题。
//这是原来的写法
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/数据库名", "root", "密码");
//修改之后的写法
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/数据库名?serverTimezone=UTC", "root", "密码"); //区别在于在数据库名之后加上了?serverTimezone=UTC