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";
  • 相关阅读:
    LinkedHashMap、HashMap和TreeMap的比较使用
    RocketMQ之Namesrv
    mysql创建、删除、查看索引
    java8 JVM堆内存(heap) 新生代 老年代 元空间垃圾回收详解
    Java中GCRoots包括哪些
    单例模式双重校验锁
    内存屏障
    LockSupport的用法及原理
    HashSet,TreeSet和LinkedHashSet的区别
    Windows常用网络命令技巧汇总
  • 原文地址:https://www.cnblogs.com/20glym/p/11650112.html
Copyright © 2011-2022 走看看