Skip to content

Cannot connect to MySQL from Azure JAVA Function #246

@steccami

Description

@steccami

Hi all,

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:

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

Here is the code:
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");

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

I am using the following library:

mysql mysql-connector-java 8.0.13

Notes:

  • 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);

  • I've already tried different mysql libraries (8.0.13, 5.1.45, 5.1.42): nothing changes;

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

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

  • I also created a fat jar file as suggested here: Access Azure SQL  #35 (comment)

Any ideas?

Thank you in advance.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions