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();
    }
}


相关文章

连接数据库的方式:第一种方式:ODBC:开放数据库连接是微软...
JDBCRequest 使用VariableNamesmysql:数据库连接池对象var...
 1.JDBCDBC(JavaDataBaseConnectivity):Java数据库连接技术...
1.需要jar包的支持:java.sqljavax.sqlmysql-conneter-java....
1.简介Activiti是一个业务流程管理(BPM)框架,它是覆盖了业务...
1.JDBC体系系统一组规范:接口JDBC接口(API)包括两个层次:...