在 Eclipse Rcp 中处理 ResultSet 值的问题
我的 ResultSet 查询是
StrQry = "select SUM(isnull(prn_amount,0))as prn_amount,SUM(isnull(adv_prn,0))as adv_prn, SUM(isnull(prv_prn,0))as prv_prn from loan_transaction_mcg where loan_id='1117'";
它给出的结果为 Sql
- prn_amount =NULL
- adv_prn =NULL
- prv_prn =NULL
当贷款 id =1117
ResultSet RsPrincipalDetail = getPaidDetail(loan_id);
while(RsPrincipalDetail.next()){
prn1 = RsPrincipalDetail.getString("prn_amount");
prn2 = RsPrincipalDetail.getString("adv_prn");
prn3 = RsPrincipalDetail.getString("prv_prn");
if(prn1.equals("")){
prn1.equals("0");
}
if(prn2.equalsIgnoreCase("")){
prn2.equals("0");
}
if(prn3.equalsIgnoreCase("")){
prn3.equals("0");
}
我尝试放置 prn1.equals(null) 但仍然 null指针异常来了。我在 prn1 上尝试了调试模式,它的值显示为 null 。
My ResultSet Query is
StrQry = "select SUM(isnull(prn_amount,0))as prn_amount,SUM(isnull(adv_prn,0))as adv_prn, SUM(isnull(prv_prn,0))as prv_prn from loan_transaction_mcg where loan_id='1117'";
It is giving the result as on Sql
- prn_amount =NULL
- adv_prn =NULL
- prv_prn =NULL
when the loan id =1117
ResultSet RsPrincipalDetail = getPaidDetail(loan_id);
while(RsPrincipalDetail.next()){
prn1 = RsPrincipalDetail.getString("prn_amount");
prn2 = RsPrincipalDetail.getString("adv_prn");
prn3 = RsPrincipalDetail.getString("prv_prn");
if(prn1.equals("")){
prn1.equals("0");
}
if(prn2.equalsIgnoreCase("")){
prn2.equals("0");
}
if(prn3.equalsIgnoreCase("")){
prn3.equals("0");
}
I tried putting prn1.equals(null) but still the null pointer exception comes. I tried in debug mode on prn1, it is showing as null as its value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里的问题是,由于数据库中的值是 NULL,当您使用 getString 将它们转换为 java 值时,它们也将为 NULL。
由于 null 与空字符串不同,因此您不能真正使用 prn.equals("")
同样使用 prn.equals(null) 也是一个坏主意,因为通常 equals 的实现方式...它将返回 false与之比较的是 null
您最好的选择是使用相等运算符来检查 null
if(prn == null)
The problem here is that since your values in database are NULL when you convert them to java values using getString they will also be null.
Since null is not the same as empty string you can not really use prn.equals("")
Also using prn.equals(null) is a bad idea as usually the way that equals is implemented ... it will return false if something that it is compared to is null
Your best bet is to use equality operator to check for null
if(prn == null)
表的列名是什么?
对我来说,这似乎可能是循环的:
并且您对loan_id的声明中似乎缺少
group by
What are the column names of the table?
For me this seems to be possibly cyclic:
and there seems to be a
group by
missing in your statement on loan_id