Bug #80497 | MySQL Statement executeBatch - batchedGeneratedKeys Field not exposed | ||
---|---|---|---|
Submitted: | 24 Feb 2016 14:57 | Modified: | 3 Mar 2016 3:11 |
Reporter: | Shriprasad Marathe | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | Connector / J | Severity: | S4 (Feature request) |
Version: | 5.0.4 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | batchedGeneratedKeys, executeBatch |
[24 Feb 2016 14:57]
Shriprasad Marathe
[1 Mar 2016 9:34]
Filipe Silva
Hi Shriprasad, Thank you for this bug report. There is already such mechanism. The JDBC specification states that the generated keys can be retrieved by consulting the ResultSet you obtain by calling Statement.getGeneratedKeys(). Most times you have to enjoin the Statement that you desire this information by using the flag Statement.RETURN_GENERATED_KEYS. In batch statements, however, there's no such option so the Connector/J driver, by default, turns it on for you. The JDBC specification doesn't enforce this, but doesn't denies it too, so you get it for free. You suggestion of getting this information as a List of ids probably won't ever happen because this depends on the JDBC specification that we don't control. I hope that helps. If you feed that is something missing or failing still, please reopen this bug or report a new one. Thank you,
[3 Mar 2016 3:11]
Shriprasad Marathe
Thanks Filip for your reply ! Please refer to http://www.docjar.com/html/api/com/mysql/jdbc/StatementImpl.java.html. If you check line #2594 and #2613 there is a mechanism that this class populates the autogeneratedkeys inside batchedGeneratedKeys (the array list object). The method at #2613 is used by executeBatch at line #1038, just afer calling executeUpdate. I debug this code and found that generated keys are set inside batchedGeneratedKeys object by these methods. Thanks & Regards, Shriprasad