JDBC连接Mysql报错.... WARN: Establishing SSL connection without server‘s identit....

错误原因

没有服务器的身份验证建立SSL连接

解决

在jdbc.properties配置文件中将url的内容改成:
url=“jdbc:mysql://localhost:3306/db3?useUnicode=true&characterEncoding=UTF-8&useSSL=false”

如果报错Exception in thread “main” com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException

如果数据库本身连接没问题,那就是mysql为8.0版本,而驱动包是5.1版本,将驱动包改成8.0以后的版本即可。

注意

jdbc 连接 mysql 8.0.11 的 jdbc.properties 配置
driver=com.mysql.cj.jdbc.Driver

jdbc测试连接mysql


import com.mysql.cj.jdbc.Driver;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

public class jdbc01 {
    //完成简单的操作
    public static void main(String[] args) throws SQLException {
        //1.注册驱动
        Driver driver = new Driver();//创建driver对象


        //2.得到连接
        String url="jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false";//连接到哪个数据库
        //指定用户名和密码,将用户名和密码放到Properties对象
        Properties properties = new Properties();
        properties.setProperty("user","root");
        properties.setProperty("password","110520");

        //获取连接
        Connection connect = driver.connect(url, properties);

        //3.执行操作
        String sql = "insert into actor values(NULL,'鲁迅','男','1941-03-14','11111')";
        Statement statement = connect.createStatement();//发送sql语句并执行
        int rows = statement.executeUpdate(sql);//如果是dml语句,返回的就是受影响的行数

        System.out.println(rows>0?"成功":"失败");

        //4.关闭连接
        statement.close();
        connect.close();
    }
}


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值