Java: retrieve key after executebatch() in H2
•
Java
I tried to retrieve the generated key from the executebatch() transaction, but I only got the last key to add
This is my code:
PreparedStatement ps_insert = conn.prepareStatement(insertQuery,PreparedStatement.RETURN_GENERATED_KEYS); for (int i = 0 ; i < 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(); //<-- Only the last key retrieved conn.commit();
What on earth did I do wrong?
Editor: sorry, I didn't mention that I use H2 in embedded mode( http://www.h2database.com/html/main.html )Database
Solution
According to H2 jdbc driver JavaDocs, this is normal behavior:
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码