当前位置: 首页 > 图文教程 > 数据库 > 数据库技巧 > JDBC大批量写入数据到SQLServer2000,记录数大于10000

数据库技巧
用计算列实现移动加权平均算法
精通数据库系列之入门-基础篇
精通数据库系列之入门-基础篇2
精通数据库系列之入门-基础篇3
精通数据库系列之入门-技巧篇1
精通数据库系列之入门-技巧篇2
精通数据库系列之入门-技巧篇3
精通数据库系列之入门-技巧篇4
写出高性能SQL语句的35条方法分析
SQL 随机查询 包括(sqlserver,mysql,access等)
在ACCESS和SQL Server下Like 日期类型查询区别
数据库中union 与union all 的区别
修改插入时间不匹配问题
收缩数据库不变小的解决方法
Access和SQL Server里面的SQL语句的不同之处
几种常用DB驱动和DB连接串小结
JDBC大批量写入数据到SQLServer2000,记录数大于10000

数据库技巧 中的 JDBC大批量写入数据到SQLServer2000,记录数大于10000


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 410 ::
收藏到网摘: n/a

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