eclipse连接mysql数据库提示The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.解决方法

异常截图:

报错原因因为安装mysql的时候默认的是美国的时区,而我们中国所在地区时区与美国不一样所导致

解决方法在url后面添加  ?serverTimezone=UTC

修改后的代码

public static void main(String[] args){
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            //数据库配置信息
            String url="jdbc:mysql://127.0.0.1:3306?serverTimezone=UTC";
            //账号
            String username="root";
            //密码
            String Password="123456";
            Connection con=DriverManager.getConnection(url,username,Password);
            System.out.println(con);
            //关闭数据库
            con.close();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

猜你喜欢

转载自www.cnblogs.com/puhongjun/p/12114959.html
今日推荐