我正在编写此实用程序代码,它将 excel 表转储到数据库中(在本例中为 postgres)。我使用 poi 的 HSSF 技术来处理 excel 表。我将 excel 工作表的每一列存储到单独的字符串类型的 ArrayLists 中。在这种情况下,当 .xls 中的列数大于 23 时,eclipse 会生成错误“堆内存已满”。我的问题是我可以将这些数组列表组合成一个集合对象,我应该使用哪种方法?
public ArrayList<String> getList(String path, String srnoStr,
String nameStr, String dobStr, String genderStr, String addressStr,
String pinStr, String mobStr, String eIdStr, String categoryStr,
String branchStr) throws IOException, SQLException {
ArrayList<String> errorList = new ArrayList<String>();
ArrayList<String> cellError = null;
// String error=null;
// OrderedMap errorMap=new LinkedMap();
// errorMap=null;
List<Cell> cells_srno = new ArrayList<Cell>();
List<Cell> cells_name = new ArrayList<Cell>();
List<Cell> cells_dob = new ArrayList<Cell>();
List<Cell> cells_gender = new ArrayList<Cell>();
List<Cell> cells_address = new ArrayList<Cell>();
List<Cell> cells_pin = new ArrayList<Cell>();
List<Cell> cells_mob = new ArrayList<Cell>();
List<Cell> cells_eId = new ArrayList<Cell>();
List<Cell> cells_category = new ArrayList<Cell>();
List<Cell> cells_branch = new ArrayList<Cell>();
try {
int srnoIndex = 0;
srnoIndex = getIndex(srno, path);
cellError = fillList(srnoIndex, srNoId, cells_srno, path);
if (cellError != null)
errorList.addAll(cellError);
cellError = null;
int nameIndex = 0;
nameIndex = getIndex(name, path);
cellError = fillList(nameIndex, nameId, cells_name, path);
if (cellError != null)
errorList.addAll(cellError);
cellError = null;
int dobIndex = 0;
dobIndex = getIndex(dob, path);
cellError = fillList(dobIndex, dobId, cells_dob, path);
if (cellError != null)
errorList.addAll(cellError);
cellError = null;
int genderIndex = 0;
genderIndex = getIndex(gender, path);
cellError = fillList(genderIndex, genderId, cells_gender, path);
if (cellError != null)
errorList.addAll(cellError);
cellError = null;
int addressIndex = 0;
addressIndex = getIndex(address, path);
cellError = fillList(addressIndex, addressId, cells_address, path);
if (cellError != null)
errorList.addAll(cellError);
cellError = null;
int pinIndex = 0;
pinIndex = getIndex(pin, path);
cellError = fillList(pinIndex, mobId, cells_pin, path);
if (cellError != null)
errorList.addAll(cellError);
cellError = null;
int mobIndex = 0;
mobIndex = getIndex(mob, path);
cellError = fillList(mobIndex, pinId, cells_mob, path);
if (cellError != null)
errorList.addAll(cellError);
cellError = null;
int eIdIndex = 0;
eIdIndex = getIndex(eId, path);
cellError = fillList(eIdIndex, eIdId, cells_eId, path);
if (cellError != null)
errorList.addAll(cellError);
cellError = null;
int categoryIndex = 0;
categoryIndex = getIndex(category, path);
cellError = fillList(categoryIndex, categoryId, cells_category,
path);
if (cellError != null)
errorList.addAll(cellError);
cellError = null;
int branchIndex = 0;
branchIndex = getIndex(branch, path);
cellError = fillList(branchIndex, branchId, cells_branch, path);
if (cellError != null)
errorList.addAll(cellError);
// System.out.println(cells);
int n = cells_srno.size();
int k = 0;
System.out.println("Total number Rows = " + (n - 1));
int j = 0;
// System.out.println("Column name=" +cells.get(0));
if (errorList.isEmpty()) {
for (int i = 1; i < n; i++) {
k = Insert(cells_srno.get(i), cells_name.get(i),
cells_dob.get(i), cells_gender.get(i),
cells_address.get(i), cells_pin.get(i),
cells_mob.get(i), cells_eId.get(i),
cells_category.get(i), cells_branch.get(i));
if (k > 0)
j++;
}
} else {
System.out.println("Error");
}
/*
* System.out
* .println("Total no. of physical row in you Excel Sheet=" + j);
* System.out
* .println("Operation Successfull!! kindly check the database!!! "
* );
*/
} catch (Exception e) {
e.printStackTrace();
}
return errorList;
}