com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
<p>i am trying to connect my java app with sql database and when i click on save button it gives me following error</p>

<pre><code>com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
</code></pre>

<p>here's my code</p>

<pre><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&gt;0)
            {
                JOptionPane.showMessageDialog(null, "Record Saved !\n");
            }
            else
            {
                JOptionPane.showMessageDialog(null, "Data Not Saved !\n");
            }
        }

        catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, e);
        }
}                                  
</code></pre>