title: Insertion of data into mysql table containing foreign key gives an error
body: <p>I have two tables in my database as :</p>
  
  <p><strong>employee_details_table:</strong></p>
  
  <ul>
  <li>employee_id int primary key ,  </li>
  <li>employee_name varchar(20)</li>
  </ul>
  
  <p><strong>employee_attendance:</strong></p>
  
  <ul>
  <li>employee_id foreign key references employee_id of
  employee_details_table ,</li>
  <li>attendance_for date ,</li>
  <li>present_or_absent varchar(6)</li>
  </ul>
  
  <p>Here is the java code to insert data into employee_attendance :</p>
  
  <pre><code>class Attendance
  {
   java.util.Date utilDate;
   java.sql.Date sqlDate;
  
   String attDate;
   int empid;
   String pa;
   Connection con=null;
   PreparedStatement statement=null;
   ResultSet rs=null;
  
   private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
   {                                         
      try
      {
      empid=Integer.parseInt(jTextField1.getText());
      sqlDate=new java.sql.Date(utilDate.getTime());
      pa=jComboBox1.getSelectedItem().toString();
      }
  
      catch(Exception e)
      {
          JOptionPane.showMessageDialog(null,e.getMessage());
      }
  
     String query = "Insert into employee_attendance (employee_id,attendance_for,present_or_absent) values (?,?,?)";
  
          try
          {
             Class.forName("com.mysql.jdbc.Driver");
             con=DriverManager.getConnection("jdbc:mysql:///hrmps?zeroDateTimeBehavior=convertToNull","root","root");
             statement=con.prepareStatement(query); 
             statement.setInt(1,empid);
             //sqlDate=new java.sql.Date(utilDate.getTime());
             statement.setDate(2,sqlDate);
             statement.setString(3, pa);
             statement.executeUpdate();
          }
  
          catch(Exception e)
          {
               JOptionPane.showMessageDialog(null,e.getMessage());
          }
  }                                        
  }
  </code></pre>
  
  <p>Whenever I try to insert data into employee_attendance , I get the exception as: </p>
  
  <blockquote>
    <p>"Cannot add or update a child row: a foreign key constraint fails"</p>
  </blockquote>