I am using Spring-Jdbc template(first timer) to create MySql repository. I have tables that use AutoIncrement columns as primary key.
I wonder if there a way to get newly generated Ids (autoInc) with each successful batch create statement?
Any pointers or sample would be a great help.
Thanks Panks
Use
getGeneratedKeys()
method from yourStatement
orPreparedStatement
object to identify the new auto generated values. Iterate the returnedResultSet
object to get the newly generated key values in the order of batch statements.This call may throw
java.sql.SQLFeatureNotSupportedException
if the JDBC driver, that you are using, does not support this method.Sample code snippet: