Use of addbatch in Java preparedstatment
JVM:-xmx1024m
Size = 1000000, which can be inserted successfully.
If you increase the size by an order of magnitude or outofmemoryerror, the memory is no longer good and the allocation is increased.
Batch Processing was originally designed to improve performance, but too much data is submitted. Due to the expansion of the heap, the addressing of the heap may lead to a reduction in performance.
If it is for transaction processing, you may wish to use a work und to create a temporary table, import data, or use addbatch, for example, each 100 rows in one batch.
Then there is a record in another table to record whether all the records have been imported successfully.
The basic idea is to use two paragraphs to submit the theory.
------------------------------
Public class app {
Public static void main (string [] ARGs) throws exception {
Connection connection = drivermanager. getconnection (
"JDBC: oracle: thin: @ localhost: 1521: XE", "Marshal", "password ");
Preparedstatement = connection
. Preparestatement ("insert into addbatch_test (ID, name) values (?,?) ");
Int size = 1000000;
For (INT I = 0; I <size; I ++ ){
Preparedstatement. setint (1, I );
Preparedstatement. setstring (2, "N" + I );
Preparedstatement. addbatch ();
}
Preparedstatement.exe cutebatch ();
Preparedstatement. Close ();
Connection. Close ();
}
}
From: http://hi.baidu.com/dyancheng/blog/item/2691422a3cad3a3f5243c1df.html