无法通过JAVA函数连接到MySQL [英] Cannot connect to MySQL from JAVA Function

查看:81
本文介绍了无法通过JAVA函数连接到MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在开发一个简单的JAVA时间触发的Azure函数.我正在尝试连接到Azure MySQL实例,但我不断收到此错误: 

I am developing a simple JAVA Time triggered Azure Function. I am trying to connect to a Azure MySQL instance but I keep getting this error: 

[信息] com.mysql.cj.jdbc.exceptions.CommunicationsException:通信链接失败
成功发送到服务器的最后一个数据包是0毫秒前.驱动程序尚未收到来自服务器的任何数据包.

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

这是代码:        

字符串url ="jdbc:mysql://XXXX.mysql.database.azure.com:3306/DBNAME?useSSL = true& requireSSL = false"; 
connect = DriverManager.getConnection(url,"user @ DBNAME","passwd");

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()

statement = connect.createStatement()

resultSet = statement.executeQuery("select * from table1");

resultSet = statement.executeQuery("select * from table1");

while(resultSet.next()){
//应用逻辑
}

while (resultSet.next()) {
//App logic
}

我正在使用以下库:

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

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

注意:

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

- The program works fine on my local machine (i.e., after adding my IP address to the MySQL firewall, I can reach the DB from my machine);

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

- I've already tried different mysql libraries: nothing changes;

-通过NodeJS实现的另一个Azure功能能够到达数据库;

- Another Azure function implemented with NodeJS is able to reach the DB;

-我试图添加功能"

- I tried to add the Function "ADDITIONAL OUTBOUND IP ADDRESSES" to the MySQL firewall: nothing changes. 

有什么想法吗?

谢谢.

推荐答案

更新:我开发了一个简单的C#Azure函数,它运行良好.这似乎是与基于Java的Azure函数环境严格相关的问题.
Update: I developed a simple C# Azure function, it works well. It seems to be a problem strictly related to the JAVA-based Azure Function env.


这篇关于无法通过JAVA函数连接到MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆