java - mysql jdbc驱动中的通信链路故障

标签 java mysql ssl jdbc

我无法使用此代码从 java 建立与 mysql 的连接

 Connection con=null;
    String dbUrl="jdbc:mysql://localhost:3300/sys?useSSL=true";
    String driver = "com.mysql.cj.jdbc.Driver";
    String userName = "root";
    String password = "cool123";

    Class.forName(driver).getDeclaredConstructor().newInstance();
    con = DriverManager.getConnection(dbUrl,userName,password);
它给我这个错误The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. The driver has not received any packets from the server. No appropriate protocol (protocol is disabled or cipher suites are inappropriate)

最佳答案

您正在尝试使用传输层安全性(TLS 或 SSL)连接到您的服务器。那是因为你的连接字符串是 ?useSSL=true .当您连接到 localhost 时,这有点奇怪。 -- 没有传输进出您的 Java 程序运行的服务器,因此使用 TLS 会花费大量额外的计算周期而没有太多好处,如果您甚至可以让它工作的话。
您的错误消息提示 TLS 不起作用(协议(protocol)被禁用或密码套件不合适是 TLS 行话。)
试试这个连接字符串:jdbc:mysql://localhost:3300/sys (无 TLS)。它可能会起作用。
然后试试这个连接字符串jdbc:mysql://localhost:3306/sys .它使用默认值。
设置 MySQL 服务器以使用 TLS takes some server engineering work and knowledge .可能没有正确完成。如果有人为您这样做,请向该人寻求帮助。

关于java - mysql jdbc驱动中的通信链路故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68891210/

相关文章:

java - 直接打开 GooglePlay 评级部分?

java - 在JavaFX中动态添加元素到窗口

mysql - 如何在mysql查询中求和

mysql - 是否可以使用在 ORDER BY 之后更新自身的变量计数器

java - 如何让 H.239 用作 SIP 服务器,在 Asterisk、Yate、SipX 或 FreeSwitch 中找不到

java - 如何通过 Selenium Webdriver 和 Java 根据 html 单击弹出窗口内的按钮

mysql - 如何修改现有列的数据类型?

java - tomcat(一个 JVM)中的每个 webapp 使用不同的 keystore

ssl - 如何使用 JBoss 6 在 RMIIO 流上启用加密

amazon-web-services - 默认 Elastic Load Balancer DNS 与 Amazon Certificate Manager 一起使用?