title: Java JDBC - Multiple prepared statement bulk insert
body: <p>Using JDBC (Oracle) I need to insert about thousand rows into each of two tables. Something like this:</p>
  
  <pre><code>"INSERT INTO TABLE_A (A_ID, A_NAME, A_LAST_NAME) VALUES (MY_SEQUENCE.NEXTVAL, ?, ?)";
  "INSERT INTO TABLE_B (B_ID, B_DESCRIPTION) VALUES (MY_SEQUENCE.CURRVAL, ?)";
  </code></pre>
  
  <p>The problem is that both tables are connected through common sequence, so that order of statements is important.</p>
  
  <p>It would be quite easy if I had only one table. In that case I used code: </p>
  
  <pre><code>String insert = "Insert into TABLE_A(A_ID, A_NAME, A_LAST_NAME) values(MY_SEQUENCE.NEXTVAL, ?, ?)";
  conn.setAutoCommit(false);
  PreparedStatement ps = conn.prepareStatement(insert);
  for(MyObject obj : myCollection) {
      ps.setString(1, obj.getName());
      ps.setString(2, obj.getLastName());
      ps.addBatch();
  }
  ps.executeBatch();
  conn.commit();
  ps.close();
  </code></pre>
  
  <p>But this approach can work only with one prepared statment and thus with only one Insert. How can I provide a solution for this problem?</p>