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

SpObserver.putSp("sessionFactory1"); 
02SimpleDateFormat fomat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
03Session s=null;
04s=daoSupport.getSessionFactory().openSession();
05Connection con=s.connection();
06Statement stmt = null;
07try {
08    stmt=con.createStatement();
09    con.setAutoCommit(false);
10    Iterator it=list.iterator();
11    int iCount = 1;
12    long start = System.currentTimeMillis();
13    while(it.hasNext()){
14        TResultWaterZId t = (TResultWaterZId)it.next();
15        StringBuffer sb = new StringBuffer();
16        sb.append("insert into T_result_water_z(schemeid,stcd,z,tm) values('");
17        sb.append(t.getSchemeid()).append("','").append(t.getStcd()).append("','");
18        sb.append(t.getZ()).append("','").append(fomat.format(t.getTm())).append("')");
19        stmt.addBatch(sb.toString());
20        if(iCount % 1000 == 0){
21            stmt.executeBatch();
22            stmt.clearBatch();
23        }
24        iCount++;
25    }
26    stmt.executeBatch();
27    stmt.clearBatch();
28    con.commit();
29    long end = System.currentTimeMillis();
30    System.out.println("addTResultWaterZId used time:"+(end-start));
31    stmt.close();
32    con.close();
33} catch (SQLException e) {
34    try {
35        con.rollback();
36    } catch (SQLException e1) {
37        e1.printStackTrace();
38    }
39    e.printStackTrace();
40}finally{
41    try {
42        stmt.close();
43        con.close();
44    } catch (SQLException e) {
45        e.printStackTrace();
46    }
47}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值