title: foreign key problem in jdbc
body: <p>I have two functions:</p>
  
  <pre><code>public void Populate_flights()
  
  public void Populate_reservations()
  </code></pre>
  
  <p>Flight and reservations are two tables.One of the entry i.e flight no. is in the reservation table. So it is a foreign key. </p>
  
  <p>Now, I need to populate the database via jbdc. So I am using: In 
  public void Populate_reservations() function: </p>
  
  <pre><code>Statement s = conn.createStatement();
  
  s.executeUpdate("DELETE FROM reservations");
  </code></pre>
  
  <p>public void Populate_flights() -:</p>
  
  <pre><code> Statement s = conn.createStatement();
  
   s.executeUpdate("DELETE FROM flights");
  </code></pre>
  
  <p>So in this way, before populating the database, all my previous entries are removed and no redundant data is there.Since, there is a foreign key in reservation table, I can't delete entries from flight first. I have to remove entries from reservation first. But reservation function is called after flight function.SO how would I make it so that it will delete all the entries.</p>
  
  <p>So it should be like this:</p>
  
  <pre><code>Statement s = conn.createStatement();
  
    s.execute("SET FOREIGN_KEY_CHECKS=0");
  
       s.executeUpdate("DELETE FROM flights");
   s.execute("SET FOREIGN_KEY_CHECKS=1");
  </code></pre>