JDBC大批量写入数据到SQLServer2000,记录数大于10000

发布时间:2022-04-22 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了JDBC大批量写入数据到SQLServer2000,记录数大于10000脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
复制代码 代码如下:

SpObserver.putSp("sessionFactory1");
SimpleDateFormat fomat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Session s=null;
s=DAOSupport.getSessionFactory().oPEnSession();
Connection con=s.connection();
statement stmt = null;
try {
stmt=con.createstatement();
con.setAutoCommIT(false);
Iterator it=list.iterator();
int iCount = 1;
long start = System.currentTimeMillis();
while(it.hasNext()){
TResultWaterZId t = (TResultWaterZId)it.next();
StringBuffer sb = new StringBuffer();
sb.append("insert into T_result_water_z(schemeid,stcd,z,tm) values('");
sb.append(t.getSchemeid()).append("','").append(t.getStcd()).append("','");
sb.append(t.getZ()).append("','").append(fomat.format(t.getTm())).append("')");
stmt.addBatch(sb.toString());
if(iCount % 1000 == 0){
stmt.executeBatch();
stmt.clearBatch();
}
iCount++;
}
stmt.executeBatch();
stmt.clearBatch();
con.COMmit();
long end = System.currentTimeMillis();
System.out.PRintln("addTResultWaterZId used time:"+(end-start));
stmt.close();
con.close();
} catch (SQLException e) {
try {
con.rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
e.printStackTrace();
}finally{
try {
stmt.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}

脚本宝典总结

以上是脚本宝典为你收集整理的JDBC大批量写入数据到SQLServer2000,记录数大于10000全部内容,希望文章能够帮你解决JDBC大批量写入数据到SQLServer2000,记录数大于10000所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:JDBC大批量