?? dbimpl.java
字號(hào):
package org.com.gather;
import java.util.*;
import java.sql.*;
public class DBImpl{
private Properties pro = null;
private Log log = null;
public DBImpl(Properties pro){
this.pro = pro;
}
public void storeToDB(Collection col)throws Exception{
if(col != null){
long start = System.currentTimeMillis();
Connection con = this.getConnection();
long end = System.currentTimeMillis();
long time = (end - start)/1000;
System.out.println("獲取連接時(shí)長(zhǎng)為 --->"+time);
Collection coll = new Vector();
String s_size = pro.getProperty("batchSize");
int size = new Integer(s_size).intValue();
int c_size = col.size();
Iterator iter = col.iterator();
String sql = "insert into dt values(?)";
PreparedStatement pstmt = con.prepareStatement(sql);
while(iter.hasNext()){
coll.add(iter.next());
if(coll.size() == size){
//System.out.println("每次寫(xiě)入數(shù)據(jù)庫(kù)的大小 ---"+size);
con.setAutoCommit(false);
Iterator it = coll.iterator();
while(it.hasNext()){
BIDR bidr = (BIDR)it.next();
pstmt.setString(1,bidr.getLoginName());
pstmt.addBatch();
}
pstmt.executeBatch();
con.commit();
coll.clear();
}
}
//System.out.println("剩下的數(shù)據(jù)大小 ---"+coll.size());
Iterator itr = coll.iterator();
con.setAutoCommit(false);
while(itr.hasNext()){
BIDR br = (BIDR)itr.next();
pstmt.setString(1,br.getLoginName());
pstmt.addBatch();
}
pstmt.executeBatch();
con.commit();
coll.clear();
System.out.println("成功插入數(shù)據(jù)庫(kù),總數(shù)量---"+col.size());
col.clear();
log.writeDebug("成功將數(shù)據(jù)插入數(shù)據(jù)庫(kù)!");
}else{
System.out.println("入庫(kù)數(shù)據(jù)量為零!");
}
}
public Connection getConnection()throws Exception{
Class.forName(pro.getProperty("driver"));
Connection con = DriverManager.getConnection(pro.getProperty("url"),pro.getProperty("username"),pro.getProperty("password"));
return con;
}
public void setLog(Log log){
this.log = log;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -