数据库 
首页 > 数据库 > 浏览文章

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

(编辑:jimmy 日期: 2024/5/19 浏览:3 次 )
复制代码 代码如下:
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();
}
}
上一篇:数据库修改多对多的中间表的记录的技巧
下一篇:几种常用DB驱动和DB连接串小结
一句话新闻
Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。