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就可以了

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

  • 相关阅读:
    .NET Interop 工具集
    关于正弦波的算法
    Windows Phone 系列 本地数据存储
    Xaml cannot create an instance of “X”
    Windows Phone 系列 使用 MVVM绑定时无法获取当前值
    Windows Phone 系列 应用程序图标无法显示
    Windows Phone 系列 WPConnect无法上网的问题
    Windows Phone 系列 使用 Windows Phone 保存铃声任务
    WP7.5提交应用
    Windows Phone 系列 动态删除ObservableCollection
  • 原文地址:https://www.cnblogs.com/itgaofei/p/9225807.html
Copyright © 2011-2022 走看看