当前位置: 移动技术网 > IT编程>数据库>其他数据库 > JDBC大批量写入数据到SQLServer2000,记录数大于10000

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

2017年12月08日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:spobserver.putsp("sessionfactory1"); simpledateformat fomat = new simpledate
复制代码 代码如下:

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

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网