我尝试使用java poi读取excel数据并尝试存储在数据库中。
我从excel中读取了这些值
Integer.parseInt(formatter.formatCellValue(row.getCell(columnNum)))
其中,excel可能在列中包含空值。所以它抛出一个错误
java.lang.NumberFormatException: For input string: ""
当尝试将excel值设置为Integer时
riskVo.setProbability(Integer.parseInt(formatter.formatCellValue(row.getCell(columnNum))));
注意:概率是一种整数数据类型。
但是如果列不为null,它接受值。
这是excel文件。
请注意,""
和NULL
之间存在差异。你得到的例外是因为空字符串""
,它与NULL
不同。
例如 :
String s = "";
s.length ()// it will return 0
但,
String s = null;
s.length ()// throw NPE.
所以,你可能首先检查,如果String
不是null
然后检查它是否为空。
if(str != null && !str.isEmpty()) {