//注册驱动
8.0
DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
5.5
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
mysql8.0和之前版本的区别,首先驱动换了,不是com.mysql.jdbc.Driver而是'com.mysql.cj.jdbc.Driver'.
连接数据库地址有变化
mysql8.0是不需要建立ssl连接的,你需要显示关闭,即url中的&useSSL=false;
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.
此错误代码需要通过配置serverTimezone配置属性 &serverTimezone=Hongkong
主要就这几个问题
8.0
Url="jdbc:mysql://localhost:3306/db3?useSSL=false&serverTimezone=Hongkong&characterEncoding=utf-8&
autoReconnect=true";
连接地址+ssl连接关闭+时区为hk+字符集为utf-8+数据库自动连接