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

2025-05-25 0 47

复制代码 代码如下:


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();
}
}

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 JDBC大批量写入数据到SQLServer2000,记录数大于10000 https://www.kuaiidc.com/51752.html

相关文章

发表评论
暂无评论