Javajdbc-how is it so slow to insert 50000 data records into mysql...

Source: Internet
Author: User
Packagecn. itcast. bath; importjava. SQL. connection; importjava. SQL. preparedStatement; importorg. junit. test; importcn. itcast. jdbc. JDBCUtils; publicclassBath {@ Testpublicvoiddemo1 () {Connectionconnnull; PreparedStatementstatnull; long... mysqljava jdbcsql data

Package cn. itcast. bath;

Import java. SQL. Connection;
Import java. SQL. PreparedStatement;

Import org. junit. Test;

Import cn. itcast. jdbc. JDBCUtils;

Public class Bath {

@ Testpublic void demo1 () {Connection conn = null; PreparedStatement stat = null; long start = System. currentTimeMillis (); try {conn = JDBCUtils. getConnection (); String SQL = "insert into person values (?,?,?) "; Stat = conn. prepareStatement (SQL); for (int I = 1; I <= 50000; I ++) {stat. setInt (1, I); stat. setString (2, "name" + I); stat. setString (3, "email" + I); stat. addBatch (); if (I % 1000 = 0) {stat.exe cuteBatch (); stat. clearBatch () ;}} catch (Exception e) {e. printStackTrace ();} finally {long end = System. currentTimeMillis (); System. out. println ("Execution time:" + (end-start); JDBCUtils. release (stat, conn );}}

}

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.