title: JDBC How to get all generated keys from single insert with many values query?
body: <p>I'm inserting multiple rows using a PreparedStatement with a single query:</p>
  
  <pre><code>String query = "insert into MyTable (a,b,c) values (?,?,?),(?,?,?),(?,?,?),(?,?,?)"; // insert 4 rows in a single query
  PreparedStatement stmt = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
  // .. here: loop to set all 4 x 3 values in my prepared statement
  </code></pre>
  
  <p>And I want to get the IDs generated by the MSSQL DB. I'm not sure which flavor of <code>execute</code> to use.</p>
  
  <p>The <code>execute()</code> method doesn't return the expected <code>ResultSet</code>:</p>
  
  <pre><code>boolean thingy = stmt.execute();
  System.out.println("execute returned ", thingy); // false: meaning no result set
  ResultSet result = stmt.getResultSet(); // result is null
  </code></pre>
  
  <p>The <code>executeUpdate()</code> method returns only one <code>ResultSet</code>:</p>
  
  <pre><code>int rowCount = stmt.executeUpdate();
  System.out.println(rowCount + " rows updated"); // 4 rows updated
  ResultSet result = stmt.getGeneratedKeys();
  // there's only one result:
  result.next(); // true
  int ID1 = result.getInt(1); // good
  result.next(); // false, no more rows
  </code></pre>
  
  <p>Is it possible to get the generated IDs with a single INSERT? I do not want to send multiple INSERT queries for performance reasons.</p>
  
  <p>DB: MS SQL Server 11 (2012)<br>
  URL: jdbc:jtds:sqlserver://...<br>
  Driver: net.sourceforge.jtds.jdbc.Driver jtds version 1.3.1</p>