【发布时间】:2020-11-23 14:22:33
【问题描述】:
我正在使用 eclipse,这是我用来连接远程 mysql 服务器的代码:
package test;
import java.sql.*;
public class test{
public static void main(String args[]){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://host:port/database?useSSL=true","username","password");
}catch(Exception e){ System.out.println(e);}
}
}
我不断收到此错误:
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
我使用了 mysql 工作台,并且能够连接到服务器。我的mysql驱动是:
mysql-connector-java-8.0.22
java version is : 1.8.0_271
远程数据库不是实际的 mysql 数据库,但我正在使用 mongodb atlas 中提供的 bi 连接器。 有没有办法知道使用哪个mysql-connectorjava?
【问题讨论】:
-
远程数据库不是真正的mysql数据库 那你为什么要使用MySQL JDBC驱动来连接它呢?还是我误解了您要做什么?
-
我正在使用 mongodb atlas ,其中包含用于 bi 的连接器。当我激活 bi 连接器时,我可以像 mysql 数据库一样连接到数据库。上面的方法曾经对我有用,但现在我不知道为什么它不起作用