代碼:
private static Boolean Function_User(Map resultMap, String sql,String tableType) {
// TODO Auto-generated method stub
Connection conn=null;
PreparedStatement insert_st=null;
int count = 0;
final int batchSize = 500;
System.out.println("開始:"+Calendar.getInstance().getTime());
try {
conn=DriverManager.getConnection(db_url,db_name,db_pwd);
conn.setAutoCommit(false);
insert_st = conn.prepareStatement(sql);
for (int i = 0; i < resultMap.get(tableType).size(); i++) {
Object obj = resultMap.get(tableType).get(i);
OrderUserSnap user = (OrderUserSnap) obj;
insert_st.setString(1, ZH_S(user.getId()));
insert_st.addBatch();
if(++count % batchSize == 0) {
insert_st.executeBatch();
insert_st.clearBatch();
}
System.out.println("tt:"+count);
}
insert_st.executeBatch();
insert_st.clearBatch();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
insert_st.close();
conn.close();
System.out.println("結束:"+Calendar.getInstance().getTime());
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return true;
}
擦 已經解決:原因是 我insert_st.setString(1, ZH_S(user.getId()));,傳遞的參數過多,Oracle的批處理個數限制為:
count=傳參個數 * 查入的數據條數
上邊設置的1000條數據,進行一次批處理,越界了~
將 final int batchSize = 500; 的值設小一點就屁事沒有