title: Perform insertion of data into multiple tables using JDBC in one function
body: <p>I need to perfom data base insertion in my spring boot webapp. What I have so far is a list of sport competitions and there respective informations.</p>
  
  <p>one competition can hold at different time the same day.
  Fist thing annoying me is how do I store this times is DB. Does a new table needed here ? <strong>(I created a date table</strong>)</p>
  
  <p>I searched around and I still don't figure out how to combine the insertion of
  competition info and its dates in my insert function at same time. </p>
  
  <p><strong>My insert function need some works, I need somme help.</strong></p>
  
  <p>this <a href="https://stackoverflow.com/questions/22000915/preparedstatement-how-to-insert-data-into-multiple-tables-using-jdbc">answer</a>  is good, but it's did not fill my requirements</p>
  
  <p><strong>My data base schema:</strong></p>
  
  <pre><code>CREATE TABLE competition ( 
    competition_id integer PRIMARY KEY,
    nom varchar(128) NOT NULL,
  ); 
  
  
  CREATE TABLE date ( 
    id integer PRIMARY KEY,
    date_time timestamptz,
    competition_id integer REFERENCES competition (competition_id)
  );
  </code></pre>
  
  <p><strong>Json data:</strong></p>
  
  <pre><code>{
      "id": "420",
      "name": "SOCCER",
      "dates": [
          "2016-05-12T03:00:00.000Z"
          "2016-05-12T04:00:00.000Z"
          "2016-05-12T05:00:00.000Z"
      ]
  },
  {
      "id": "220",
      "name": "BASKETBALL",
      "dates": [
          "2016-05-12T03:00:00.000Z"
          "2016-05-12T04:00:00.000Z"
      ]
  }
  </code></pre>
  
  <p><strong>My competition Class:</strong></p>
  
  <pre><code>public class Competition{
      private int id;
      private String name;
      private String[] dates;
      // setters ... getters
  }
  </code></pre>
  
  <p><strong>Function to insert data :</strong> </p>
  
  <pre><code>private static final String INSERT_STMT =
        " insert into competition (id, name)"
      + " values (?, ?)"
      ;  
  
  
  public int insert(Competition competition) {
      return jdbcTemplate.update(conn -&gt; {
        PreparedStatement ps = conn.prepareStatement(INSERT_STMT);
        ps.setInt(1, competition.getId());
        ps.setString(2, competition.getName());
        return ps;
      });
  
  
      // insert also in date table ???
    }
  </code></pre>