zoukankan      html  css  js  c++  java
  • 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";
  • 相关阅读:
    输出重定向
    echo带颜色输出
    shell学习视频目录
    css盒模型
    jQuery表格模糊搜索
    mysql基础语法3
    mysql基础语法2
    mysql基础语法1
    pyspider框架的使用
    quill富文本框图片上传重写
  • 原文地址:https://www.cnblogs.com/20glym/p/11650112.html
Copyright © 2011-2022 走看看