sapientconceptions
asked on
getGeneratedKey() only returns last record of inserted batch
I have a batch that inserts more than one record at a time. After the batch call I call getGeneratedKeys on the preparedStatement, but it only returns the last record inserted (MySQL database)...
//sample code
/* code to delare preparedStatement and code to set values and add to batch */
int[] updateCounts = object.executeBatch();
ResultSet rs = object.getGeneratedKeys ();
//sample code
/* code to delare preparedStatement and code to set values and add to batch */
int[] updateCounts = object.executeBatch();
ResultSet rs = object.getGeneratedKeys ();
Don't think you can use getGeneratedKeys() when using batch processing.
ASKER
ok, but I thought that was the whole reason for the method (especially since it's named with an 's' on the end)...
I guess I'll have to create my own id's and send with the insert, but then the question becomes -- how can I easily get the last id in the database?
I guess I'll have to create my own id's and send with the insert, but then the question becomes -- how can I easily get the last id in the database?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
objects actually answered your last question a couple of months ago ;-)
https://www.experts-exchange.com/questions/20733689/How-to-retrieve-the-auto-increment-primary-key-value-from-a-mysql-'insert'-statement.html
https://www.experts-exchange.com/questions/20733689/How-to-retrieve-the-auto-increment-primary-key-value-from-a-mysql-'insert'-statement.html
ASKER
Objects,
Sometimes you just need someone else to tell you the obvious! Thanks for the help.
Sometimes you just need someone else to tell you the obvious! Thanks for the help.