Home > Back-end >  Consult the JDBC bulk insert performance, thank you
Consult the JDBC bulk insert performance, thank you

Time:05-26

https://www.cnblogs.com/DreamDrive/p/5757693.html
The above link, insert line 1 million takes 24 seconds, governor of very short
Can say very slow

As my test program, is the above links to insert 100000 rows, President of 10 a few times
According to the number of bytes to calculate, I INSERT more bytes on such as link
But I only took 1 seconds in notebooks,
What reason is this? Why is my test so fast?

Long SSS=System. CurrentTimeMillis ();
String STRSQL="insert into the test values (?,?,?,?,? ,? ,? ,?) ";
PreparedStatement prest=conn. PrepareStatement (STRSQL, ResultSet. TYPE_SCROLL_SENSITIVE, ResultSet. CONCUR_READ_ONLY);
For (int I=1; I & lt;=100000; I++)
{
Prest. SetString (1, "1001100" + I);
Prest. SetString (2, "hello hello" + I);
Prest. SetString (3, "XXXX" + I);
Prest. SetString (4, "hello, hello hello hello hello hello hello hello hello hello hello hello" + I);
Prest. The addBatch ();
}
Prest. ExecuteBatch ();
Long eee=System. CurrentTimeMillis () - SSS;
System. The out. Println (" \ nbatch insert Time spend: "+ eee);

In addition to the bulk insert, and more efficient to write code? Mybatis?
Seemingly complicated
thank you

CodePudding user response:

Insert into table1 (column1, column2,... ) values
(a1, a2,... ),
(b1, b2,... ),
(c1, c2,... )
Pay attention to the length of the SQL statement

CodePudding user response:

reference 1/f, one born in response:
insert into table1 (column1, column2,... ) values
(a1, a2,... ),
(b1, b2,... ),
(c1, c2,... )
Pay attention to the length of the SQL statement can

Thank you, I would like to ask is the performance, is what I very quickly, while others write online said slowly

CodePudding user response:

You performed only once, in other words, you establish a session and database set up only once, so fast, you for loop eventually generates SQL is my hair of SQL
Insert into table1 (column1, column2,... ) values
(a1, a2,... ),
(b1, b2,... ),
(c1, c2,... ),
.
(c100000 c200000,... - a total of one hundred thousand data to insert into the database, the current way of inserting data, most efficient
He is every 1000 in https://www.cnblogs.com/DreamDrive/p/5757693.html, this document is to perform a, equivalent to 100
Insert into table1 (column1, column2,... ) values
(a1, a2,... ),
(b1, b2,... ),
(c1, c2,... ),
.
(c1000, c2000,... ) -- -- -- -- -- -- --
1000 dataSo slowly, but this should pay attention to the length of the SQL, mysql has asked to execute the SQL statement length, through max_allowed_packet Settings, the default of 1 m
  • Related