【无标题】

mysql常见问题处理

The server time zone value ‘Öйú±ê׼ʱ¼ä‘ is unrecognized or represents more than one time zone.

转载: The server time zone value ‘Öйú±ê׼ʱ¼ä‘ is unrecognized or represents more than one time zone.
在这里插入图片描述

Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure问题解决

转载: Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure问题解决
在这里插入图片描述

MySQL8.0连接url

转载: MySQL8.0连接url
在这里插入图片描述

数据库连接测试用例(代码)

@Test
    public void run() throws ClassNotFoundException, SQLException {

        //1,加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");

        //2、用户信息和URL
        String url = "jdbc:mysql://localhost:3306/uedu?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC";
        String username = "root";
        String password = "123456";

        //3、连接成功,数据库对象  Connection代表数据库
        Connection connection = DriverManager.getConnection(url, username, password);

        //4、执行SQL对象  statement 执行sql对象
        Statement statement = connection.createStatement();

        //5、执行SQL对象 去 执行SQL,可能存在结果,查看返回结果
        String sql = "SELECT * FROM user";
        ResultSet resultSet = statement.executeQuery(sql);//返回结果集,结果封装了我们全部查询的结果

        while (resultSet.next()) {
            System.out.println("彭于晏,你的mysql连接成功.......");
        }

        //6、释放连接

        resultSet.close();
        statement.close();
        connection.close();
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值