java - Discovering which records of a batch update failed -


i making batch update of 1000 records in java using jdbc. out of them 800 records updated sucessfully , 200 falied . want check batch update query 200 records failed b updated , insert them in database using batch insert . how can achieve ?

executebath() method statement returns array of integers (one integer per command executed). each integer represents update count. if 1 or greater, update done successfully; if 0, no record updated respective command.

example:

list<yourclass> objectstoupdate = getobjectstoupdate();  (yourclass object : objectstoupdate) {     string updatecommand = generateupdatecommand(object);     statement.addbatch(updatecommand); } int[] results = statement.executebatch();  list<yourclass> notupdated = new arraylist<yourobject>();  (int = 0; < results.length; i++) {     if (results[i] == 0) {         notupdated.add(objectstoupdate.get(i));     } } 

that demonstrate algorithm. consider using preparedstatement instead of statement.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -