java - Using getGeneratedKeys with batch inserts in MySQL with Connector/J -


using connector/j, batch insert master table followed batch insert details table (preparedstatement.executebatch() both). haven't found information online, i'm looking feedback people have experience this.

  1. can use statement.getgeneratedkeys() ids of newly inserted rows in master table can use them foreign keys in detail inserts?

  2. what if not every query resulted in insert (e.g. there insert ignore or insert ... on duplicate key update query)? row in statement.getgeneratedkeys() every statement, or new ones?

  3. what statement.getgeneratedkeys() return there error 1 of inserted master records, , continuebatchonerror set true in connection string?

  4. are there differences in related behavior between connector/j versions 5.0.x vs 5.5.x? mysql 5.0 vs 5.1?

  5. any there other issues or gotchas should aware of?

  6. is there better way this?

well, ran tests. connector/j 5.1 , mysql 5.1.42, observe following:

  1. statement.getgeneratedkeys() works expected inserts

  2. if row inserted or updated (the update count array returned executebatch() returns '1' or '2'), statement.getgeneratedkeys() have key row. if row not modified (insert ignore or insert ... on duplicate key update results in no-op, executebatch() returns 3), there no key.

  3. the resultset returned getgeneratedkeys have entries inserted rows, per (2). there not generated key row failed inserts (where update count value statement.execute_failed)

  4. ?

  5. be careful rewritebatchedstatements in jdbc connection string. if set true, failures result in every row in rewritten "chunk" treated though had failed. 1 way handle iterate failed rows , retry them without batching.

  6. ?


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -