JDBC ExecuteBatch throws an abnormal stop

Source: Internet
Author: User

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!!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.