建议在没有服务器身份验证的情况下建立SSL连接错误解决

建议在没有服务器身份验证的情况下建立SSL连接错误解决,第1张

今天在学习java数据库连接时候,出现警告:

翻译: 

不建议在没有服务器身份验证的情况下建立SSL连接。根据MySQL 5.5.45+、5.6.26+和5.7.6+的要求,如果未设置显式选项,默认情况下必须建立SSL连接。为了符合不使用SSL的现有应用程序,verifyServerCertificate属性设置为“false”。您需要通过设置useSSL=false显式禁用SSL,或者设置useSSL=true并为服务器证书验证提供信任库。

写的代码如下
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

public abstract class JDBC01 {
    public static void main(String[] args) throws SQLException {
        //1.libs下的jbdc那些类是厂商需要达到标准的一些类
        //注册驱动
        com.mysql.jdbc.Driver driver = new com.mysql.jdbc.Driver();

        //连接数据库
        String url = "jdbc:mysql://127.0.0.1:3306/java_test1?"
        //将用户名与密码放入Propertise对象
        Properties properties = new Properties();
        properties.setProperty("user","root");
        properties.setProperty("password","hmz");
        //获取连接
        //connect 网络连接
        Connection connect = driver.connect(url, properties);

        String sql = "insert into java_table1 value(3,'韩信','深圳')";
        Statement statement = connect.createStatement();//帮助发生sql语句
        int rows = statement.executeUpdate(sql); //返回是影响的行数
        System.out.println(rows>0?"成功":"失败");
        //关闭连接
        statement.close();
        connect.close();
    }}

其中很明显这行代码有问题

 String url = "jdbc:mysql://127.0.0.1:3306/java_test1";

解决方案:将url后的内容做点修改

  String url="jdbc:mysql://localhost:3306/java_test1?useUnicode=true&characterEncoding=utf-8&useSSL=false";

编译通过

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/729355.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-27
下一篇 2022-04-27

发表评论

登录后才能评论

评论列表(0条)

保存