commit size in spring batch insert
i have a list of 500,000 records .i am using t开发者_如何学运维he batch update code to insert data in database.Should i send those many records in a single batch insert? or i should use commit size to commit at interval of say 50000.how can i set commit size?
try
{
strInsertQry = "INSERT INTO file_upload_tbl_xm"
+ "(rec_id,fupload_id)"
+ "values" + "(UPLOAD_S.nextval,"
+ " ? " //
+ ")";
getJdbcTemplate().getDataSource().getConnection().setAutoCommit(false);
int[] updateCounts = getJdbcTemplate().batchUpdate(strInsertQry,new BatchPreparedStatementSetter()
{
public void setValues(PreparedStatement ps, int i) throws SQLException {
FileDataDTO dataDTO = (FileDataDTO)lstSqlFinalData.get(i);
ps.setInt(1,dataDTO.getIntFuploadId());
}
public int getBatchSize() {
return lstSqlFinalData.size();
}
} );
//intResult = updateCounts[0];
// getJdbcTemplate().getDataSource().getConnection().commit();
return true;
}
I always do commit size of 500. I got into that practice after I used "SQL Manager for MySQL". There the export and import defaulted to 500 and I notice performance improvement on my commits when restoring and when problems occured it was easy to resume without having the console just hang.
I'm doing it HQL as well as in SQL.
精彩评论