复制代码 代码如下:
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();
}
}
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,大批量,写入数据
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
岱庙资源网 Copyright www.zgmyg.com
暂无“JDBC大批量写入数据到SQLServer2000,记录数大于10000”评论...
更新日志
2024年05月15日
2024年05月15日
- 松田圣子SeikoMatsuda《SEIKOJAZZ3》2024[24bit-WAV+CUE]
- 老任极其重视NS2保密工作 疑似为其代号又建了个代号
- 世嘉舅妈透露任天堂新项目代号 或为《塞尔达传说:荒野之息》新机增强版
- EA计划游戏内置广告 博主整活《使命召唤》“幽灵之死”插播广告
- 群星《柏林之声3》[WAV+CUE][654M]
- 张学友《4合一珍藏集》[FLAC][1.4G]
- 刘亮鹭《此情可待+江湖情+江湖笑》3CD合集[WAV+CUE][1.3G]
- 麦田守望者.1997-麦田守望者【红星生产社】【WAV+CUE】
- 陈蕾.2024-念【华纳】【FLAC分轨】
- 与非门.2010-10乐园【中唱】【WAV+CUE】
- 崩坏星穹铁道2.2枪火的试炼怎么解锁 枪火试炼隐藏挑战攻略
- 崩坏星穹铁道2.2时间的试炼怎么解锁 时间试炼隐藏挑战攻略
- dnf纳瑟乌森林怎么去
- 群星-阿里郎故乡三韵-2011-WAV分轨
- 王力宏《力宏二十二十周年唯一精逊【Hi-Res】24-96FLAC