【发布时间】:2016-06-04 05:41:33
【问题描述】:
我有从 sql 数据库中获取数据(两列)的 java 程序。我有一个包含三列的 excel 文件。 excel文件的第二列和结果集的第一列已经进行了比较。如果它们匹配,我想将数据集第二列的值写入 excel 文件的第四列。到目前为止我有这个代码。问题是,这只检查第一个单元格而不移动到下一个单元格。请帮忙
int row = 0;
while(row < 50) {
cell = sheet.getRow(row).getCell(1);
String cellValue = cell.getStringCellValue();
while (results.next()) {
String name = results.getString("StationName");
if(cellValue.equals(name)) {
System.out.println(results.getString("StationName"));
System.out.println("Strings matched and values written !!!! ");
newCell = sheet.getRow(row).getCell(3);
int Bal = results.getInt(2);
newCell.setCellValue(Bal);
} else {
System.out.println(results.getString("StationName"));
System.out.println("Strings not matched!!! ");
}
}
row = row + 1;
}
【问题讨论】: