Use of addbatch in Java preparedstatment

Source: Internet
Author: User

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

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.