首先这里产生了两个错误,一个是jdbc加载驱动问题,另一个是time zone即mysql服务驱动和JDBC驱动时区不同步。
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.
java.sql.SQLException: 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.
问题解决
- 问题1直接按照错误中提示将
com.mysql.jdbc.Driver
改为com.mysql.cj.jdbc.Driver
即可。 - 问题2时区不同步,在mysql数据库的url中添加
?serverTimezone=UTC
使驱动时区同步。如下:其中/mysql是我自己创建的数据库名字String url = "jdbc:mysql://localhost:3306/mysql?serverTimezone=UTC";