title: jdbc batch insert and query vs single inserts with gernerated key
body: <p>I want to insert alot of rows into a table that generates the keys automatically. JDBC doesn't guarantee that getting the generated keys will work on a batch update.</p>
  
  <p><code>It is implementation-defined as to whether getGeneratedKeys will return
  generated values after invoking the executeBatch method.</code> (JDBC 4.0 Specification 2006, p. 135).</p>
  
  <p>I have got two choices. Insert every row separately and get the key.Or do a batch insert and then query for the keys.</p>
  
  <p>To avoid round-tripping for querying multiple keys I could use this approach <a href="http://www.javaranch.com/journal/200510/Journal200510.jsp#a2" rel="nofollow">here</a>. Having e.g. 5 prepared statements with different sizes. And then breaking my "batch query" into the smallest possible statement.</p>
  
  <p>What is the faster method?</p>