我尝试使用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))));
注意:概率是一种整数数据类型。
但是如果列不为空,它接受值。
这是excel文件。
答案 0 :(得分:1)
请注意,CompilerGenerated
和""
之间存在差异。由于空字符串NULL
与""
不同,因此您获得异常的是。
例如:
NULL
但是,
String s = "";
s.length ()// it will return 0
因此,如果String s = null;
s.length ()// throw NPE.
不是String
,您可以先检查一下,然后检查它是否为空。
null