2

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 source 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");

I am using the following library:

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

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

Any ideas?

Thank you in advance.

8
  • did you try a different version of the same connector package? Looks like it has an history of such connectivity issues with azure mysql stackoverflow.com/questions/44620692/… stackoverflow.com/questions/53095542/… Commented Nov 12, 2018 at 10:13
  • Thank you. I've already tried different package versions but the error is still there. The point is that the same JAVA code works fine on my local machine (i.e., I can connect to the remote Azure DB). It seems something related to specific Azure/networking configurations. Commented Nov 12, 2018 at 11:35
  • 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. Commented Nov 12, 2018 at 16:25
  • Did you find the solution for this problem ? Commented Feb 5, 2019 at 22:40
  • I contacted MS support but unfortunately they did not manage to provide any solution. They told me that JAVA is still in preview so they closed the ticket. This problem is very weird. I tried many different configurations/jdbc libs but nothing changed. The weird thing is that I can reach the Azure MySQL DB when running the same code on my local machine. Commented Feb 6, 2019 at 13:58

1 Answer 1

0

5.1.31 MySQL-connector-java version Worked for me.

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

Connecting MySQL Azure with Java

Sign up to request clarification or add additional context in comments.

5 Comments

It does not work for me :( I tried to re-create the App but nothing changes. My DB has SSL status: ENABLED. Maybe something related to the SSL connection?
My Url : jdbc:mysql://xxxxxxx:3306/{mydb}?serverTimezone={zone}&trustServerCertificate=true&encrypt=true&hostNameInCertificate=*.database.windows.net
Thank you for sharing your connection string. Here is what I did: I tried your suggestion and obtained the following error jdbc:mysql://xxx.mysql.database.azure.com:3306/xxx?serverTimezone=UTC&trustServerCertificate=true&encrypt=true&hostNameInCertificate=*.database.windows.net Error: java.sql.SQLException: SSL connection is required. Please specify SSL options and retry..
The previous problem was probably due to the SSL setup so I changed your string in this way: jdbc:mysql://xxx.mysql.database.azure.com:3306/xxx?useSSL=true&serverTimezone=UTC&trustServerCertificate=true&encrypt=true&hostNameInCertificate=*.database.windows.net Error: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Is it possible for you to share the java project? Of course I am not asking you for the entire code ;-) but a "simplified" version of it where I can see the maven setup anche code used for the DB connection? Many thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.