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.