title: Spring JDBC - Bulk insert targeting multiple tables
body: <p>Using JDBC (Oracle), I need to insert thousands of rows to three different tables. Basically, I want to execute 3 insert SQL statement, one after the other, in a loop.</p>
  
  <p>I read <a href="https://stackoverflow.com/questions/7195665/java-jdbc-multiple-prepared-statement-bulk-insert">this link</a> and I would like to know which implementation is better (in terms of execution time) :</p>
  
  <ol>
  <li>Execute the first SQL statement in a batch and retrieve the generated keys</li>
  <li>Execute the second SQL statement using the generated keys from step 1 in a batch and retrieve new generated keys</li>
  <li>Exercute the third SQL statement using both generated keys from step 1 and 2</li>
  </ol>
  
  <p>Or looping through each record to insert and for each record executing the 3 SQL statements one after the other.</p>
  
  <p>I know the first implementation is database-dependent (since <code>ResultSet.getGeneratedKeys()</code> is not supported by every database). Maybe there is a third implementation I have not thought of?</p>
  
  <p>I want to use a single connection so, for both implementation, I would first get a connection, do every insert and finally commit and close the connection.</p>
  
  <p>Also, I wonder if I can use any of Spring JDBC abstraction. The second implementation seems possible with Spring JdbcTemplace (wrapping the method with <code>@Transactional</code> in order to use the same connection) but the first one looks difficult since the method batchUpdate of JdbcTemplate does not return the generated keys.</p>