JDBC大批量寫入數(shù)據(jù)到SQLServer2000,記錄數(shù)大于10000
更新時間:2009年12月08日 00:29:44 作者:
JDBC大批量寫入數(shù)據(jù)到SQLServer2000,記錄數(shù)大于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();
}
}
相關文章
DBeaver操作所有數(shù)據(jù)庫管理工具使用詳解
這篇文章主要為大家介紹了一款操作所有數(shù)據(jù)庫工具DBeaver使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-07-07一篇文章教會你使用gs_restore導入數(shù)據(jù)
gs_restore是GaussDB(DWS)提供的針對gs_dump導出數(shù)據(jù)的導入工具,下面這篇文章主要給大家介紹了關于如何通過一篇文章教會你使用gs_restore導入數(shù)據(jù)的相關資料,需要的朋友可以參考下2022-09-09