手机
当前位置:查字典教程网 >编程开发 >数据库其他 >JDBC大批量写入数据到SQLServer2000,记录数大于10000
JDBC大批量写入数据到SQLServer2000,记录数大于10000
摘要:复制代码代码如下:SpObserver.putSp("sessionFactory1");SimpleDateFormatfomat=new...

复制代码 代码如下:

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】相关文章:

SQL SERVER的字段类型说明

SQL server 2005的表分区

数据库学习建议之提高数据库速度的十条建议

数据库分页查询方法

8 种常用的 NoSQL 数据库系统对比分析

使用Bucardo5实现PostgreSQL的主数据库复制

数据库查询中遭遇特殊字符导致问题的解决方法

多种获取远程连接access数据库的方法

SQL Prompt--绝好的SQL语法提示工具

超大数据量存储常用数据库分表分库算法总结

精品推荐
分类导航