Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Inserting huge volume of records in JDBC

User_19BPUSep 30 2015 — edited Oct 1 2015

Hi,

   I am inserting a batch of records say 100000 records using PreparedStatement, whether it is better use to executeUpdate() as below or go with a batch update by adding the batches? Whether batchInsert offers better performance than executeUpdate()? Or we will insert the records in an iterative manner using small batch size? 

  for (TestData testDataModel : testDataList) { // 100000 data

  PreparedStatement preStatement = null;

  try {

  preStatement = connectionObj.prepareStatement(CUSTOMER_QUERY);

  preStatement.setString(1, testDataModel .getCustomerId());

  preStatement.setDate(2, testDataModel .getCreationDate());

  preStatement.setString(3, testDataModel .getDisplayName());

  preStatement.setString(4, testDataModel .getAddress());

  preStatement.executeUpdate();

  } catch (SQLException sqlExp) {

  }finally{

  if(preStatement != null){

  try {

  preStatement.close();

  } catch (SQLException sqlExp) {

  }

}

}

Also, whether we need to close the connection and prepared statement with in the for loop or outside as there many multiple connections based on the record count? Please clarify.

Thanks.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 29 2015
Added on Sep 30 2015
6 comments
3,643 views