title: java: retrieve keys after executeBatch() in H2
body: <p>I am trying to retrieve generated keys from an <code>executeBatch()</code> transaction but I only get the last key to be added.</p>
  
  <p>this is my code:</p>
  
  <pre><code>        PreparedStatement ps_insert = conn.prepareStatement(insertQuery, PreparedStatement.RETURN_GENERATED_KEYS);          
          for (int i = 0 ; i &lt; adding_dates.length ; i++){
              ps_insert.setInt(1, Integer.parseInt(consultant_id));
              ps_insert.setDate(2, adding_dates[i]);
              ps_insert.setInt(3, Integer.parseInt(room_id));
              ps_insert.addBatch();
          }
          ps_insert.executeBatch();
          ResultSet rs = ps_insert.getGeneratedKeys(); //&lt;-- Only the last key retrieved
          conn.commit();          
  </code></pre>
  
  <p>What am I doing wrong? </p>
  
  <p>EDIT: Apologies for not mentioning that I use H2 (<a href="http://www.h2database.com/html/main.html" rel="nofollow">http://www.h2database.com/html/main.html</a>) database in embedded mode. </p>