【发布时间】:2021-08-23 10:43:52
【问题描述】:
我无法使用此代码从 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)
【问题讨论】:
-
你的错误中是否有causeby子句?您无法连接到正在运行的 mysql 实例。它在运行吗?用户名/密码是否正确?有防火墙吗?
-
@SusanMustafa 用户名和密码正确但是我使用的是 vpn 有什么关系吗?
-
3300 是使用的正确端口吗?一般是3306
-
@SusanMustafa 是的
-
尝试从命令行(不使用 java)telnet 到它 telnet localhost 3300 或 telnet localhost 3306 看看是否可以连接。如果您可以连接,则需要查看代码中的其他内容....但如果您无法 telnet,则它是您的网络/vpn