gpt4 book ai didi

遇到 null 时 Java 结果集错误

转载 作者:行者123 更新时间:2023-12-01 19:14:51 24 4
gpt4 key购买 nike

我有一些代码将查询的结果集放入二维数组中。但是,当数组遇到结果集中的 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++;
}

最佳答案

除了你做了类似的事情之外,没有任何原因会导致错误

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

只需将其替换为

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

或者更好地为此替换编写一个容空方法。

关于遇到 null 时 Java 结果集错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7153993/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com