나는 Excel에서 데이터를 읽고 데이터베이스에 저장해야하는 프로그램이 있습니다. LinkedHashmap을 사용하여 각 셀을 문자열로 읽습니다. 내 엑셀 파일은, 상기 데이터가 포함오름차순 ID를위한 트리 맵
ID 명칭 급여
5 크리스틴 2,349,000
6 폴리나 1,000
7 로라 12,587,458
8 EFI 34,567
43 짐 45878
내가 프로그램을 실행할 때 나는 내가 원하는 결과를 성공적으로 얻었습니다. 내가 지금 가지고있는 문제는 오름차순 ID로 데이터베이스에 데이터를 저장하려고한다는 것입니다. 나는 이것을 어떻게 할 것인가? 나는 treeMap을 사용해야한다는 것을 알고 있지만 정확히 어떻게 사용합니까? 아래 코드는 데이터베이스에 데이터를 저장하는 코드입니다. 엑셀 파일의 두 번째 행에서 데이터를 읽습니다.
private static LinkedHashMap[] parseExcelColumnData(List sheetData) {
LinkedHashMap[] tousRows = new LinkedHashMap[sheetData.size() - 1];
for (int rowCounter = 1; rowCounter < sheetData.size(); rowCounter++) {
List list = (List) sheetData.get(rowCounter);
LinkedHashMap<String, Integer> tableFields = new LinkedHashMap(list.size());
String str;
String[] tousFields = new String[list.size()];
int i = 0;
for (int j = 0; j < list.size(); j++) {
Cell cell = (Cell) list.get(j);
if (cell != null) {
if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
tableFields.put(String.valueOf(cell
.getNumericCellValue()), cell.getCellType());
} else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
tableFields.put(cell.getStringCellValue(), cell
.getCellType());
} else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
tableFields.put(String.valueOf(cell
.getBooleanCellValue()), cell.getCellType());
}
}
}
tousRows[rowCounter - 1] = tableFields;
}