码迷,mamicode.com
首页 > 数据库 > 详细

JDBC连接时出现的两个错误

时间:2019-10-10 20:20:24      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:stack   call   manual   config   加载   local   automatic   trace   figure   

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

错误代码:

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";

 

JDBC连接时出现的两个错误

标签:stack   call   manual   config   加载   local   automatic   trace   figure   

原文地址:https://www.cnblogs.com/20glym/p/11650112.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!