我有500,000条记录的列表。我正在使用批量更新代码在数据库中插入数据。我应该在单个批量插入中发送这些记录吗?或者我应该使用提交大小以50000的间隔提交。我可以设置提交大小吗?
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;
}
答案 0 :(得分:0)
我总是提交 500 的大小。在使用“SQL Manager for MySQL”后,我进入了这种做法。导出和导入默认为 500 ,我发现在恢复时我的提交性能有所改善,当出现问题时,如果没有控制台挂起,很容易恢复。
我正在使用HQL和SQL。