遇到 null 时 Java 结果集错误

发布于 2024-11-30 15:15:45 字数 1547 浏览 0 评论 0原文

我有一些代码将查询的结果集放入二维数组中。但是,当数组遇到结果集中的 null 时,就会出错。我该如何解决这个问题?

  query = "SELECT * FROM E_CMS WHERE BOXADDR_AREA IS NULL ORDER BY CBOXID ASC ";
  rs = stmt.executeQuery(query);

    //insert the table into the 2 dimensional array
    while (rs.next()) {
    e_cms_Array[count][0] = rs.getString("CBOXID");
    e_cms_Array[count][1] = rs.getString("CBOXADD").replace("'","");
    e_cms_Array[count][2] = rs.getString("MFLPU");
    e_cms_Array[count][3] = rs.getString("SATLPU");
    e_cms_Array[count][4] = rs.getString("BOXTYPE");
    e_cms_Array[count][5] = rs.getString("SVCCLASS");
    e_cms_Array[count][6] = rs.getString("LOCATION_TYPE").replace("'","");
    e_cms_Array[count][7] = rs.getString("CHANGE_DATE");
    e_cms_Array[count][8] = rs.getString("DEL_FLAG");
    e_cms_Array[count][9] = rs.getString("DECAL_PRINT_DT");
    e_cms_Array[count][10] = rs.getString("BOXADDR_AREA").replace("'","");
    e_cms_Array[count][11] = rs.getString("LASTMF_AREA_O");
    e_cms_Array[count][12] = rs.getString("LASTSAT_AREA_O");

    System.out.println(count + " :: " + 
      e_cms_Array[count][0]+"|"+
      e_cms_Array[count][1]+"|"+
      e_cms_Array[count][2]+"|"+
      e_cms_Array[count][3]+"|"+
      e_cms_Array[count][4]+"|"+
      e_cms_Array[count][5]+"|"+
      e_cms_Array[count][6]+"|"+
      e_cms_Array[count][7]+"|"+
      e_cms_Array[count][8]+"|"+
      e_cms_Array[count][9]+"|"+
       e_cms_Array[count][10]+"|"+
      e_cms_Array[count][11]+"|"+
      e_cms_Array[count][12]);

    count++;
    }

I have some code that is putting the resultset from a query into a 2 dimensional array. However when the array encounters a null from the resultset, it errors. How do I fix this?

  query = "SELECT * FROM E_CMS WHERE BOXADDR_AREA IS NULL ORDER BY CBOXID ASC ";
  rs = stmt.executeQuery(query);

    //insert the table into the 2 dimensional array
    while (rs.next()) {
    e_cms_Array[count][0] = rs.getString("CBOXID");
    e_cms_Array[count][1] = rs.getString("CBOXADD").replace("'","");
    e_cms_Array[count][2] = rs.getString("MFLPU");
    e_cms_Array[count][3] = rs.getString("SATLPU");
    e_cms_Array[count][4] = rs.getString("BOXTYPE");
    e_cms_Array[count][5] = rs.getString("SVCCLASS");
    e_cms_Array[count][6] = rs.getString("LOCATION_TYPE").replace("'","");
    e_cms_Array[count][7] = rs.getString("CHANGE_DATE");
    e_cms_Array[count][8] = rs.getString("DEL_FLAG");
    e_cms_Array[count][9] = rs.getString("DECAL_PRINT_DT");
    e_cms_Array[count][10] = rs.getString("BOXADDR_AREA").replace("'","");
    e_cms_Array[count][11] = rs.getString("LASTMF_AREA_O");
    e_cms_Array[count][12] = rs.getString("LASTSAT_AREA_O");

    System.out.println(count + " :: " + 
      e_cms_Array[count][0]+"|"+
      e_cms_Array[count][1]+"|"+
      e_cms_Array[count][2]+"|"+
      e_cms_Array[count][3]+"|"+
      e_cms_Array[count][4]+"|"+
      e_cms_Array[count][5]+"|"+
      e_cms_Array[count][6]+"|"+
      e_cms_Array[count][7]+"|"+
      e_cms_Array[count][8]+"|"+
      e_cms_Array[count][9]+"|"+
       e_cms_Array[count][10]+"|"+
      e_cms_Array[count][11]+"|"+
      e_cms_Array[count][12]);

    count++;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

筱果果 2024-12-07 15:15:45

没有任何原因会导致该错误,除非您执行

  e_cms_Array[count][1] = rs.getString("CBOXADD").replace("'","");

“仅将其替换为”

  String s = rs.getString("CBOXADD");
  e_cms_Array[count][1] = s==null ? s : s.replace("'","");

或更好地为此替换编写一个空容忍方法之类的操作。

There's no reason for the error, except for you doing things like

  e_cms_Array[count][1] = rs.getString("CBOXADD").replace("'","");

Just replace it by

  String s = rs.getString("CBOXADD");
  e_cms_Array[count][1] = s==null ? s : s.replace("'","");

or better write a null-tolerant method for this replacement.

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