【问题标题】:java mysql , chosing the connection driverjava mysql,选择连接驱动
【发布时间】: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 数据库一样连接到数据库。上面的方法曾经对我有用,但现在我不知道为什么它不起作用

标签: java mysql


【解决方案1】:

您是否为您的 java 应用程序尝试了 mysql 连接器依赖 jar?

如果你的项目是基于 maven 的,你可以直接从这里https://mvnrepository.com/artifact/mysql/mysql-connector-java 在你的 pom.xml 文件中添加这个依赖。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-17
    • 1970-01-01
    • 1970-01-01
    • 2014-07-28
    • 2012-01-16
    • 1970-01-01
    • 2015-06-02
    • 1970-01-01
    相关资源
    最近更新 更多