java - mysql 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 不起作用(协议已禁用或密码套件不合适是 TLS 行话。)
试试这个连接字符串:( jdbc:mysql://localhost:3300/sys
无 TLS)。它可能会起作用。
然后试试这个连接字符串jdbc:mysql://localhost:3306/sys
。它使用默认值。
设置 MySQL 服务器以使用 TLS需要一些服务器工程工作和知识。可能没有正确完成。如果有人为您这样做,请向该人寻求帮助。
推荐阅读
- javascript - 每次调用时重复 setTimeout() 更改的函数
- wso2is - WSO2-IS 5.10.0 - IDTokenIssuerID - deployment.toml
- r - 尝试在 Google Colab 中运行 DDPLY 时出错
- excel - 有没有办法只更改数据标签中文本的某些部分的颜色?
- c# - 处理 VarVector
ML.NET 中的特征列 - javascript - 如何在 react-native 中导航到嵌套屏幕
- html - 克服 contenteditable 中不一致
的选择行为 - exchangewebservices - 仅使用 EWS 阅读所有标记未设置为“标记完成”的电子邮件
- ios - RxSwift 对 Observable 的扩展,其中 Element 是 Result<>
- swift - swift 委托变量始终为 nil