Link to home
Start Free TrialLog in
Avatar of sapientconceptions
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 ();
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Don't think you can use getGeneratedKeys() when using batch processing.
 
Avatar of sapientconceptions
sapientconceptions

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?
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Objects,

Sometimes you just need someone else to tell you the obvious!  Thanks for the help.