As the project prepares to go online, a large amount of test data is prepared to test the performance of the new project, but it is less likely to use stored procedures and database transactions for data insertion.
The first use of the simplest Java for Loop statement keeps the Add object, but found that the efficiency is too low, to insert millions of of data estimates a day, and then found on the Internet, find a direct use of JDBC directly into the data, take down to try to find performance although better than the new object, But the efficiency is also very low.
Can only find, finally found a very high, that is, using the batch submission method of SQL execution, this 1 million data is about 30 seconds or so.
[Java] View Plain copy print? Public static void insertrelease () { long begin = new date () getTime (); String sql = "insert into tb_big_data (Count, create_time, random) VALUES (?, sysdate (), ?) "; try { conn.setautocommit (false); preparedstatement pst = conn.preparestatement ( SQL); for (int i = 1; i <= 100; i++) { for (int k = 1; k <= 10000; k++) { pst.setlong (1, k * i); pst.setlong (2, k * i); pst.addbatch (); } pst.executebatch (); conn.commit (); } pst.close (); Conn.close (); } catch (sqlexception e) { e.printstacktrace (); } long end = new date () getTime (); system.out.println ("cast : " + (end - begin) / 1000 + "s"); }
Original address: http://blog.csdn.net/frinder/article/details/38830723