当前环境:
jdk_1.8.0
mysql-connector-java-8.0.16.jar
问题一:
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.
解决方法:
Driver driver = "com.mysql.jdbc.Driver";
===>Driver driver = "com.mysql.cj.jdbc.Driver";
详见https://www.cnblogs.com/lexiaofei/p/10591730.html
问题二:
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:
String url = "jdbc:mysql://127.0.0.1:3306/mybatis";
===>String url = "jdbc:mysql://127.0.0.1:3306/mybatis?serverTimezone=GMT";
测试连接:
import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;
import java.util.Properties;
public class test {
public static void main(String[] args) throws SQLException{
Driver driver = new com.mysql.cj.jdbc.Driver();
String url = "jdbc:mysql://127.0.0.1:3306/mybatis?serverTimezone=GMT";
Properties info = new Properties();
info.put("user", "root");
info.put("password", "null");
Connection conn = driver.connect(url,info);
System.out.println(conn);
}
}