简体   繁体   English

com.mysql.cj.jdbc.exceptions.CommunicationsException:通信链接失败

[英]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 我试图将我的Java应用程序与sql数据库连接,当我单击“保存”按钮时,出现以下错误

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

This error generally occur because of following reason. 通常由于以下原因而发生此错误。 1.hostname in JDBC URL is not correct. 1.JDBC URL中的主机名不正确。 2.port number is not correct. 2.端口号不正确。 3.db server is not up. 3.db服务器未启动。 for these take following step 1. give full JDBC url or test with ping. 为此,请执行以下步骤1.提供完整的JDBC URL或使用ping测试。 2. check in my.cnf of mysql. 2.检查mysql的my.cnf。 3. start the db. 3.启动数据库。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring MySQL com.mysql.cj.jdbc.exceptions.CommunicationsException:通信链接失败 - Spring MySQL com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure com.mysql.cj.jdbc.exceptions.CommunicationsException:Z05B60653C41A8BDA4E6DFC3AFD31A214E6D中的通信链路故障 - com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure in docker com.mysql.cj.jdbc.exceptions.CommunicationsException:Z9CE3D468890F9087C项目中的通信链路故障 - com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure in JPA project com.mysql.cj.jdbc.exceptions.CommunicationsException:GCP 中的通信链路故障 - CloudSQL - com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure in GCP - CloudSQL com.mysql.cj.jdbc.exceptions.CommunicationsException:通信链路故障 2021 - com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure 2021 com.mysql.cj.jdbc.exceptions.CommunicationsException:尝试构建 spring 引导时通信链接失败 docker 图像 - com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure when trying to build spring boot docker image com.mysql.cj.jdbc.exceptions.CommunicationsException:通信链路故障。 驱动程序没有收到来自服务器的任何数据包 - com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure. The driver has not received any packets from the server com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败? - com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure? com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败 - com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure com.mysql.cj.jdbc.exceptions.CommunicationsException:从服务器成功收到的最后一个数据包是XXXXXXXXXXXX毫秒前 - com.mysql.cj.jdbc.exceptions.CommunicationsException: The last packet successfully received from the server was XXXXXXXXXXXX milliseconds ago
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM