Java efficiently BULK INSERT SQL Server database

Source: Internet
Author: User
Tags bulk insert

@Testpublic void Clockingin_img () throws EXCEPTION{DBJDBC IDB = DBMASTER.GETIDB ("JXT"); List<jxt_pay_info> pays=idb.getbeanlist ("SELECT top 100000 * from Jxt_pay_info", jxt_pay_info.class);// You can test it with IDB .... Big Data insertion method String sql = "INSERT into Jxt_pay_info1 (ID, card_id, Pay_money, Pay_time, Pay_date, pay_address, school_id, sour ce_id, Lasttime, Card_sn,paid_after) VALUES (?,?,?,?,?,?,?,?,?,?,?) "; Connection Connection = IDB. DbConnection; PreparedStatement PS = connection.preparestatement (SQL), final int batchsize = 1000;int count = 0;long Start=system.curren Ttimemillis ();    System.err.println ("Start"); for (Jxt_pay_info pay:pays) {ps.setint (1, Pay.getid ());    Ps.setstring (2, pay.getcard_id ());    Ps.setfloat (3, Pay.getpay_money ());    Ps.setstring (4, Pay.getpay_time ());    Ps.setstring (5, Pay.getpay_date ());    Ps.setstring (6, pay.getpay_address ());    Ps.setstring (7, pay.getschool_id ());    Ps.setstring (8, pay.getsource_id ());    Ps.setstring (9, Pay.getlasttime ()); Ps.setint (10,PAY.GETCARD_SN ());    Ps.setstring (one, Pay.getpaid_after ());    Ps.addbatch (); }ps.executebatch (); Insert remaining recordsps.close (); Connection.close ();D BMASTER.CLOSEIDB (IDB); Long End=system.currenttimemillis ( ); System.err.println ("End" + (End-start));}}

  

Insert 1000:347 ms

Insert 1W Bar: 4086 ms

Insert 10W Bar: 47953 ms

Similarly, batch updates can also be used with this method, except that they are not inserted quickly,

Update 1000:90 seconds

Update 100:9 seconds

Java efficiently BULK INSERT SQL Server database

Related Article

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.