JDBC大批量寫(xiě)入數(shù)據(jù)到SQLServer2000,記錄數(shù)大于10000
更新時(shí)間:2009年12月08日 00:29:44 作者:
JDBC大批量寫(xiě)入數(shù)據(jù)到SQLServer2000,記錄數(shù)大于10000
復(fù)制代碼 代碼如下:
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語(yǔ)句提高處理速度
- Java批量修改文件名的實(shí)例代碼
- java 下執(zhí)行mysql 批量插入的幾種方法及用時(shí)
- java文件重命名(文件批量重命名)實(shí)例程序代碼分享
- Java實(shí)現(xiàn)文件批量重命名具體實(shí)例
- Java快速批量移動(dòng)文件的實(shí)現(xiàn)方法
- Java 批量刪除html中注釋內(nèi)容的方法
- 實(shí)例講解Java批量插入、更新數(shù)據(jù)
- python實(shí)現(xiàn)JAVA源代碼從ANSI到UTF-8的批量轉(zhuǎn)換方法
- java實(shí)現(xiàn)jdbc批量插入數(shù)據(jù)
相關(guān)文章
數(shù)據(jù)庫(kù)的三級(jí)模式和兩級(jí)映射介紹
在這里大家一定要注意三級(jí)模式中的概念模式對(duì)應(yīng)的是數(shù)據(jù)庫(kù)設(shè)計(jì)的邏輯模型,而不是概念模型(E-R模型),一定不要弄混了2012-10-10大數(shù)據(jù)之Spark基礎(chǔ)環(huán)境
本篇文章開(kāi)始介紹Spark基礎(chǔ)知識(shí),包括Spark誕生的背景,應(yīng)用環(huán)境以及入門(mén)案例等,感興趣的同學(xué)可以參考閱讀本文2023-04-04DBeaver操作所有數(shù)據(jù)庫(kù)管理工具使用詳解
這篇文章主要為大家介紹了一款操作所有數(shù)據(jù)庫(kù)工具DBeaver使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07關(guān)于SQL中PIVOT函數(shù)的使用方法詳解
SQL Server中的PIVOT函數(shù)是一種用于將行數(shù)據(jù)轉(zhuǎn)換為列數(shù)據(jù)的表格旋轉(zhuǎn)函數(shù),這篇文章主要給大家介紹了關(guān)于SQL中PIVOT函數(shù)的使用方法,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-12-12一篇文章教會(huì)你使用gs_restore導(dǎo)入數(shù)據(jù)
gs_restore是GaussDB(DWS)提供的針對(duì)gs_dump導(dǎo)出數(shù)據(jù)的導(dǎo)入工具,下面這篇文章主要給大家介紹了關(guān)于如何通過(guò)一篇文章教會(huì)你使用gs_restore導(dǎo)入數(shù)據(jù)的相關(guān)資料,需要的朋友可以參考下2022-09-09