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

数据库技巧
数据库删除完全重复和部分关键字段重复的记录
SQL服务器面临的危险和补救.读[十种方法]后感.
SQLite不支持Right Join的解决办法GROUP BY
mssql注入躲避IDS的方法
本地SQL注射攻略分析曝光
数据库 左连接 右连接 全连接用法小结
以前架征途时的合区的SQL语句代码备份
sql语句中where 1=1的作用
dba_indexes视图的性能分析
推荐Sql server一些常见性能问题的解决方法
带参数的sql和不带参数的sql存储过程区别
SQL语句详细说明[部分]
PostgreSQL8.3.3安装方法
三表左连接查询的sql语句写法
MSSQL自动同步设置方法
mssql数据同步实现数据复制的步骤
SQL嵌套查询总结
sql2005可实时监测数据库版本控制SQL的触发器
sql 中将日期中分秒化为零的语句
SQL 注入式攻击的本质

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 411 ::
收藏到网摘: 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();
}
}