When you do a batch update, you find:
Addbatch (SQL);
ExecuteBatch throws an exception, the remaining SQL is not updated, that is, the exception before the storage, after the exception, even if there is no executable SQL execution.
Baidu Information After understanding: This is DBMS database management system control, and some DBMS after the exception, the rest of the SQL will be executed, and some DBMS exception after the rest of the storage.
My method of improvement is as follows: public static Boolean Bachinsertdata (List<string> sqllist) {Boolean bool = false; Connection conn = null;
Public Static BooleanBachinsertdata (list<string>sqllist) { BooleanBOOL =false; Connection Conn=NULL; Statement STM=NULL; Try{conn=mydao.getconnection (); Conn.setautocommit (false); STM=conn.createstatement (); for(String sql:sqllist) {stm.addbatch (SQL); } stm.executebatch (); Conn.commit (); BOOL=true; } Catch(Exception e) {if(Einstanceofbatchupdateexception) {batchupdateexception bexception=(batchupdateexception) e; int[] s =bexception.getupdatecounts (); Logger.info ("Update failed data:" +Sqllist.get (s.length)); if(s.length+1<sqllist.size ()) {List<String> sList = sqllist.sublist (s.length+1, Sqllist.size ()); Bachinsertdata (sList); } }Else{e.printstacktrace (); Try { if(STM! =NULL) Stm.close (); } Catch(SQLException ex) {ex.printstacktrace (); } Try{conn.close (); } Catch(SQLException ex) {ex.printstacktrace (); } } } finally { Try { if(STM! =NULL) Stm.close (); } Catch(SQLException ex) {ex.printstacktrace (); } Try{conn.close (); } Catch(SQLException ex) {ex.printstacktrace (); } } returnbool; }
I did not know that wow ah ah ah, a lot to change!!!