JDBC连接时出现的两个错误

 这两个错误都是因为版本的更新导致的;

错误代码:

package FirstTest;
import java.sql.*;
public class FirstJDBC {
    public static void main(String[] args) throws SQLException {
        try {
            //加载驱动类
            Class.forName("com.mysql.jdbc.Driver");
       //建立连接
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test.jdbc","root","123456");
            System.out.println(con);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}

错误一:

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'

错误二:

Exception in thread "main" 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.

该错误为由系统时间错误引起,只需要在访问数据库时在Url后面加上以下的语句即可:

OLD_URL = "jdbc:mysql://localhost:3306/test.jdbc";
NEW_URL = "jdbc:mysql://localhost:3306/test.jdbc?serverTimezone=GMT%2B8";

猜你喜欢

转载自www.cnblogs.com/20glym/p/11650112.html