微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何实现JDBC大批量写入数据到SQLServer2000中记录数大于10000

这篇文章主要介绍“如何实现JDBC大批量写入数据到sqlServer2000中记录数大于10000”,在日常操作中,相信很多人在如何实现JDBC大批量写入数据到sqlServer2000中记录数大于10000问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何实现JDBC大批量写入数据到sqlServer2000中记录数大于10000”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

复制代码 代码如下:


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大批量写入数据到sqlServer2000中记录数大于10000”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注编程之家网站,小编会继续努力为大家带来更多实用的文章

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐