在 Eclipse Rcp 中处理 ResultSet 值的问题

发布于 2024-11-15 22:31:36 字数 1069 浏览 1 评论 0原文

我的 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

  1. prn_amount =NULL
  2. adv_prn =NULL
  3. 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

  1. prn_amount =NULL
  2. adv_prn =NULL
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绝不放开 2024-11-22 22:31:36

这里的问题是,由于数据库中的值是 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)

人生百味 2024-11-22 22:31:36

表的列名是什么?

对我来说,这似乎可能是循环的:

SUM(isnull(prn_amount,0))as prn_amount

并且您对loan_id的声明中似乎缺少group by

What are the column names of the table?

For me this seems to be possibly cyclic:

SUM(isnull(prn_amount,0))as prn_amount

and there seems to be a group by missing in your statement on loan_id

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文