Java BULK Insert Data (Oracle)

Source: Internet
Author: User
Tags bulk insert

  1. 8 seconds to add 20,000 data in bulk.
  2. try {
  3. String url = "Jdbc:oracle:thin: @IP: 1521:ORCL"; //ORCL is the SID of the database
  4. String user = "Oracle";
  5. String password = "Oracle";
  6. StringBuffer sql = new StringBuffer ();
  7. Sql.append ("INSERT into Ex_log (ex_log_id,ex_log_date) VALUES (?,?)");
  8. Class.forName ("Oracle.jdbc.driver.OracleDriver");
  9. Connection con = (Connection) drivermanager.getconnection (Url,user,password);
  10. //Turn off transaction autocommit
  11. Con.setautocommit (false);
  12. Long startTime = System.currenttimemillis ();
  13. PreparedStatement PST = (preparedstatement) con.preparestatement (sql.tostring ());
  14. For (int i = 0; i < list.size (); i++) {
  15. Exlog Exlog = (exlog) list.get (i);
  16. Pst.setstring (1, Exlog.getexlogid ());
  17. Pst.setstring (2, Exlog.getexlogdate ());
  18. //Add a SQL command to the command list
  19. Pst.addbatch ();
  20. }
  21. //Perform batch updates
  22. Pst.executebatch ();
  23. //Statement execution complete, commit this transaction
  24. Con.commit ();
  25. Long endTime = System.currenttimemillis ();
  26. System.out.println ("spents:" + (Endtime-starttime));
  27. Pst.close ();
  28. Con.close ();
  29. } catch (ClassNotFoundException e) {
  30. E.printstacktrace ();
  31. } catch (SQLException e) {
  32. E.printstacktrace ();
  33. }

Java BULK Insert Data (Oracle)

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.