1

I am facing an issue to connect to azure MySQL database with Java. Though whenever I am connecting with same database with MySQL workbench the connection working as expected.

To connect the same I tried below codes where used both of the url string mentioned.

Class.forName("com.mysql.jdbc.Driver");
// String url = "jdbc:mysql://***-mysqldbserver.mysql.database.azure.com:3306/medilegaldb?autoReconnect=true";
String url ="jdbc:mysql://***-mysqldbserver.mysql.database.azure.com:3306/medilegaldb?useSSL=true&requireSSL=false";
Connection con = DriverManager.getConnection(url, "user", "pass");

Azure Subscription Details

Need help to identify the issue.

5
  • 1
    What error do you get? Commented Nov 1, 2018 at 5:19
  • Did you open up port 3306 in both directions on your Azure instance? You'll need to do that in order for your MySQL instance to be reachable from the outside. And of course, please verify that you are using the right credentials. Commented Nov 1, 2018 at 5:20
  • Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure - This is the error I m getting. Also about credentials I am using the same configuration when connecting though workbench and everything working. Commented Nov 1, 2018 at 6:01
  • Problem I am getting is only with the Java configuration. Please suggest. Commented Nov 1, 2018 at 6:26
  • This problem is specific to mysql jar file. Now it's resolved. Commented Nov 1, 2018 at 9:07

1 Answer 1

5

Which version of MySQL-connector-java did you use? I used 5.1.6 and encountered the same error. But if I use 5.1.31, it works. Please let me know if this fix your issue.

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.31</version>
    </dependency>
Sign up to request clarification or add additional context in comments.

2 Comments

Yes. This works fine for me. Thanks for the quick help.
can u please give a specific reason on this issue, as I have also facing the same

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.