我应该对我的应用程序进行压力测试,为此我需要在表中存储6000万条记录。我要遵循的方法是,首先初始化Connection类的实例,然后使用该Connection通过PreparedStatement使用for循环插入数据,然后在每插入500行之后提交并重置连接。
使用此功能,我每分钟可以插入约150条记录。我只想知道是否还有其他更优化的方法,以使执行所需的时间最少
使用jdbc批处理插入:
PreparedStatement ps = conn.prepareStatement(sql);
int count = 0;
for(loop construct here) {
count++;
ps.setString(1,someString);
// ... and so forth
ps.addBatch();
if (count%500 ==0)
ps.executeBatch()
}
ps.executeBatch();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句