title: How to get auto generated keys of batch insert statement?
body: <p>I want to INSERT batch of records in a database (i.e. DB2) using JDBC batch statement and then obtain the auto generated IDs of inserted rows. How can I achieve using JDBC API?</p>
  
  <p>Example Code:</p>
  
  <pre><code>String SQL_INSERT = "INSERT INTO TABLE1 (CURRENT_TIMESTAMP) VALUES (?) ";
  
  Connection connection = DriverManager.getConnection("jdbc:db2://localhost:900/DATABASE");
  PreparedStatement statement = connection.prepareStatement(SQL_INSERT, Statement.RETURN_GENERATED_KEYS);
  
  // first batch
  statement.setTimestamp(1, getCurrentTimestamp());
  statement.addBatch();
  
  //  second batch
  statement.setTimestamp(1, getCurrentTimestamp());
  statement.addBatch();
  
  int[] insertedRows = statement.executeBatch();
  
  ResultSet generatedKeys = statement.getGeneratedKeys();
  </code></pre>
  
  <p>The batch statement executes successfully, all rows inserted into database. But when calling <code>getGeneratedKeys()</code> to retrieve generated keys, it returns an empty <code>ResultSet</code>. Any idea, why?</p>