• Mysql最新jar包连接数据库报错


    今天准备开始从最基础的jdbc复习复习,于是就在maven里下载了最新的mysql jar包:

    jar包:

    连接数据库查询

         Connection connection=null;
            PreparedStatement preparedStatement=null;
            ResultSet resultSet=null;
            try {
                Class.forName("com.mysql.jdbc.Driver");
                connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/myshool?characterEncoding=utf-8&useSSL=false","root","root");
                String sql="select * from student where name= ? ";
                preparedStatement=connection.prepareStatement(sql);
                preparedStatement.setString(1,"小明");
                resultSet=preparedStatement.executeQuery();
                while (resultSet.next()){
                    System.out.println(resultSet.getString("id")+" " +resultSet.getString("name"));
                }
    
    
            }
            catch (ClassNotFoundException e) {
                e.printStackTrace();
           } catch (SQLException e) {
                e.printStackTrace();
            }

    在main方法写完后提交报错信息:

    也就是报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.

    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后添加useSSL=false&serverTimezone=Hongkong 

    之后试了一下果然有效,但是为什么呢?

    后来查了一下,说是用mysql最新的jar包造成的原因,这个版本的包需要加时区,还有若不加useSSL=false,就会警告:

    若有:

    这个警告,那么把com.mysql.jdbc.Driver改成com.mysql.cj.jdbc.Driver就可以了

    最后运行出来的结果就是:

  • 相关阅读:
    分享一下用终端的命令来恢复丢失的硬盘分区表 (转)
    Smart Link
    underrun || overrun
    mtr命令详解诊断网络路由
    tracert traceroute
    OE1、OE2、ON1、ON2路由有什么区别?
    GRE tunnel 2
    【SAP HANA】新建账户和数据库(2)
    【SAP HANA】SAP HANA开篇(1)
    入职一周
  • 原文地址:https://www.cnblogs.com/itgaofei/p/9225807.html
Copyright © 2020-2023  润新知