I am using preparedstatement batch update/insert to store data into database. But it is taking 3 minutes to persist 1000 entries into SQL Server Database. Am wondering if there is a way to improve the performance. Please check my code below:
SQL UPDATE STATEMENT
String sqlUpdate = "UPDATE details set a=? , b=? , c=? , d=?, e=? where f=?";
updatePstmt = conn.prepareStatement(sqlUpdate);
public static void updateCustomerDetailByBatch(HashMap<String, String []> updateCustDetails ) {
final int BATCH_SIZE=1000;
int batchCtr = 1;
try{
conn.setAutoCommit(false);
MAFLogger.info("Number of Customer details to be updated: "+ updateCustDetails.size());
for (Map.Entry<String, String []> custEntry: updateCustDetails.entrySet()) {
String x = custEntry.getValue()[0];
String y = custEntry.getValue()[1];
String z = custEntry.getKey();
String a = custEntry.getValue()[2];
String b = custEntry.getValue()[3];
String c = custEntry.getValue()[4];
updatePstmt.setString(1, x);
updatePstmt.setString(2, y);
updatePstmt.setString(3, z);
updatePstmt.setString(4, a);
updatePstmt.setString(5, b);
updatePstmt.setString(6, c);
updatePstmt.addBatch();
if (batchCtr % BATCH_SIZE == 0) {
MAFLogger.debug("Batch Ctr is : " + batchCtr+ " Updated Batch ");
updatePstmt.executeBatch();
}
batchCtr++;
}
if (batchCtr % BATCH_SIZE != 0 ) {
MAFLogger.debug("Execute remaining batch update statement contents: "+ batchCtr);
updatePstmt.executeBatch();
}
conn.setAutoCommit(true);
}catch (SQLException sqlE) {
MAFLogger.error("Batch update statement problem : " + sqlE);
}
}
I have read different articles about adding and answers here in SO such as these link1 , link2 and link3 but there is no change. Appreciate if you can help out.
I am using Microsoft JDBC Driver downloadable on their website "sqljdbc_4.1.5605.100_enu.tar.gz"
Table Index
index_name index_description index_keys
PK_CC_Details_TEMP clustered, unique, primary key located on PRIMARY f