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
Post a Comment