//批量插入
public boolean maintainRecordBatch(
String sqlMaintain,
ArrayList vectorList)
throws Exception {
boolean flag = true;
try {
openConnection();
int start = 0;
while(start < vectorList.size()){
start = this.oneBatch(start,500,vectorList,sqlMaintain);
}
} catch (Exception sqle) {
sqle.printStackTrace();
throw new DAOException(sqle);
} finally {
closeConnection(false);
}
return flag;
}
private int oneBatch(int start,int times,ArrayList vectorList,String sqlMaintain) throws DAOException{
try {
Object valueObj = null;
PreparedStatement ps = connection.prepareStatement(sqlMaintain);
for (int j = start;j<times+start && j<vectorList.size(); j++) {
Vector element = (Vector) vectorList.get(j);
int i = 0;
for (Enumeration valueList = element.elements();
valueList.hasMoreElements();
){
i++;
valueObj = valueList.nextElement();
setColumnValue(i, valueObj, ps);
}
ps.addBatch();
}
ps.executeBatch();
ps.clearBatch();
return times+start;
} catch (SQLException e) {
e.printStackTrace();
throw new DAOException(e);
}
}
public boolean maintainRecordBatch(
String sqlMaintain,
ArrayList vectorList)
throws Exception {
boolean flag = true;
try {
openConnection();
int start = 0;
while(start < vectorList.size()){
start = this.oneBatch(start,500,vectorList,sqlMaintain);
}
} catch (Exception sqle) {
sqle.printStackTrace();
throw new DAOException(sqle);
} finally {
closeConnection(false);
}
return flag;
}
private int oneBatch(int start,int times,ArrayList vectorList,String sqlMaintain) throws DAOException{
try {
Object valueObj = null;
PreparedStatement ps = connection.prepareStatement(sqlMaintain);
for (int j = start;j<times+start && j<vectorList.size(); j++) {
Vector element = (Vector) vectorList.get(j);
int i = 0;
for (Enumeration valueList = element.elements();
valueList.hasMoreElements();
){
i++;
valueObj = valueList.nextElement();
setColumnValue(i, valueObj, ps);
}
ps.addBatch();
}
ps.executeBatch();
ps.clearBatch();
return times+start;
} catch (SQLException e) {
e.printStackTrace();
throw new DAOException(e);
}
}