Hướng dẫn com.mysql.cj.jdbc.exceptions.communicationsexception: communications link failure

i am trying to connect my java app with sql database and when i click on save button it gives me following error

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

here's my code

        name = full_name_input.getText[];
        Fname = father_name_input.getText[];
        cnic = father_cnic_input.getText[];
        DOB = Integer.parseInt[DOB_input.getText[]];
        Class_V = Integer.parseInt[class_input.getText[]]; 
        prsnt_add = present_add_input.getText[];
        city = city_input.getText[];
        province = radio_text;
        Connection conn = null;
        PreparedStatement pst = null;

        try
        {
            Class.forName["com.mysql.jdbc.Driver"];
            conn = DriverManager.getConnection["jdbc:mysql:///UserDetails", "root", "sahanj"];
            pst = conn.prepareStatement["insert into UserDetails values [?,?,?,?,?,?,?,?]"];

            pst.setString[1, name];
            pst.setString[2, Fname];
            pst.setString[3, cnic];`enter code here`
            pst.setInt[4, DOB];
            pst.setInt[5, Class_V];
            pst.setString[6, prsnt_add];
            pst.setString[7, city];
            pst.setString[8, province];

            int x = pst.executeUpdate[];

            if [x>0]
            {
                JOptionPane.showMessageDialog[null, "Record Saved !\n"];
            }
            else
            {
                JOptionPane.showMessageDialog[null, "Data Not Saved !\n"];
            }
        }

        catch[Exception e]
        {
            JOptionPane.showMessageDialog[null, e];
        }
}                                  

com.mysql.cj.jdbc.exceptions.communicationsexception communications link failure can be resolved with a little help from our experts.

At Bobcares, we offer solutions for every query, big and small, as a part of our Server Management Services.

Let’s take a look at how our Support Team is ready to help customers resolve com.mysql.cj.jdbc.exceptions.communicationsexception communications link failure message.

Resolved: com.mysql.cj.jdbc.exceptions.communicationsexception communications link failure

Have you been running into communications link failure messages?

SQLException: Connection refused or Connection timed out

Or

CommunicationsException: Communications link failure

If yes, it usually means that the database is not reachable. According to our MySQL Support Techs, the communications link failure message may be due to one of the following reasons:

  • The wrong IP address of the JDBC URL
  • Unrecognized hostname in JDBC URL
  • Missing or inaccurate port number in DNS server
  • DB server is down
  • TCP/IP connections not accepted by DB server
  • DB server does not have any more connections

Fortunately, we can resolve the communications link failure message with these steps:

  1. To begin with, verify and test with the ping command.
  2. Next, refresh DNS. Alternatively, we can use the IP address in JDBC URL instead.
  3. Verify this according to my.cnf of MySQL DB.
  4. After that, the database and check if mysqld started without the –skip-networking option.
  5. Then, restart the database and fix the code to close the connections.
  6. Next, disable the firewall or enable the firewall to allow the port. We can add the TLS protocol to the connection string
    jdbc:mysql://localhost:3306/database_name?enabledTLSProtocols=TLSv1.2

Furthermore, we can update the IP address with these steps to resolve the communications link failure message:

    1. First, open /etc/mysql/my.cnf file.
    2. Then, change the bind-address as bind-address = 0.0.0.0.

Alternatively, restart mysql daemon and mysql services to resolve the failure message.

However, if you are still running into communications link failure message, our MySQL Support Techs are just a click away.

[Need assistance with another query? We are available 24/7.]

Conclusion

In a nutshell, our skilled Support Engineers at Bobcares demonstrated how to resolve com.mysql.cj.jdbc.exceptions.communicationsexception communications link failure message.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

Chủ Đề