zoukankan      html  css  js  c++  java
  • 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就可以了

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

  • 相关阅读:
    hdu 1247 Hat’s Words (字典树)
    测试
    hdu 1285 确定比赛名次 (拓扑)
    hdu 3172 Virtual Friends (并查集)
    hdu 3635 Dragon Balls (并查集)
    [Shell学习笔记] read命令从键盘或文件中获取标准输入(转载)
    Shell脚本下条件测试(eq.ne.....)(转载)
    每天一个 linux命令(35):ln 命令(转载)
    ubuntu中 python升级 (转载)
    source命令用法(转载)
  • 原文地址:https://www.cnblogs.com/itgaofei/p/9225807.html
Copyright © 2011-2022 走看看