JDBC BULK Insert operation (Addbatch)

Source: Internet
Author: User
Tags bulk insert

1 /**2 * BULK Insert3  */4 @Test5      Public voidTestinsert () {6Connection conn=NULL;7Statement st=NULL;8PreparedStatement pst=NULL;9         Try {Tenconn=dbutils.getconn (); OneConn.setautocommit (false);//things can't be submitted automatically Ast=conn.createstatement (); -             LongStart =System.currenttimemillis (); -String sql= "INSERT into STU1 values (?,?)"; thepst=conn.preparestatement (SQL); -             intCount=0; -              for(inti=1;i<=10008;i++){ -Pst.setint (1, i); +Pst.setstring (2, "Tmo" +i); - Pst.addbatch (); +count++; A                 if(count==2000){ at Pst.executebatch (); - Pst.clearbatch (); -Count=0; -                 } -             } -Pst.executebatch ();//increase in the last less than 2000 in Pst.clearbatch (); -Conn.commit ();//Commit a transaction toSystem.out.println (System.currenttimemillis ()-start); +}Catch(SQLException e) { -             //TODO auto-generated Catch block the e.printstacktrace (); *         } $         finally{Panax NotoginsengDbutils.closeall (NULL, ST, conn); -         } the}

JDBC BULK Insert operation (Addbatch)

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.