Using Connector/J, I would like to do a batch insert into a master table followed by a batch insert into a details table (PreparedStatement.executeBatch()
for both). I haven't found much information online, so I'm looking for any feedback from people that have experience with this.
Can I use
Statement.getGeneratedKeys()
to get the IDs of the newly inserted rows in the master table so that I can use them as foreign keys in the detail inserts?What if not every query resulted in an insert (e.g. there was an
insert ignore
orinsert ... on duplicate key update
query)? Will I get a row inStatement.getGeneratedKeys()
for every statement, or only for the new ones?What will
Statement.getGeneratedKeys()
return there is an error with one of the inserted master records, andcontinueBatchOnError
is set totrue
in the connection string?Are there any differences in the related behavior between Connector/J versions 5.0.x vs 5.5.x? What about MySQL 5.0 vs 5.1?
Any there any other issues or gotchas that I should be aware of?
Is there a better way to do this?