2

我正在开发一个简单的 JAVA 时间触发 Azure 函数。

我正在尝试连接到 Azure MySQL 实例,但我不断收到此错误:

[Information] 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.

这是源代码:

String url="jdbc:mysql://XXXX.mysql.database.azure.com:3306/DBNAME?useSSL=true&requireSSL=false";
connect = DriverManager.getConnection(url, "user@DBNAME", "passwd"); 
statement = connect.createStatement(); 
resultSet statement.executeQuery("select * from table1");

我正在使用以下库:

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>

笔记:

  • 该程序在我的本地机器上运行良好(即,将我的 IP 地址添加到 MySQL 防火墙后,我可以从我的机器访问数据库);

  • 我已经尝试过不同的 mysql 库:没有任何变化;

  • 另一个用 NodeJS 实现的 Azure 功能可以访问数据库;

  • 我尝试将“附加出站 IP 地址”功能添加到 MySQL 防火墙:没有任何变化。

有任何想法吗?

先感谢您。

4

1 回答 1

0

5.1.31 MySQL-connector-java 版本为我工作。

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.31</version>
</dependency>

将 MySQL Azure 与 Java 连接起来

于 2019-02-06T14:27:28.283 回答