Java: how to assign variables if the result is null?
•
Java
This works:
String address1 = HtmlUtil.escape(rs.getString("address1"));
... but I don't want to show "null" So I tried this, and it didn't work:
String address1 = HtmlUtil.escape(rs.getString("address1") || "");
Is the best choice to use it:?
String address1 = HtmlUtil.escape(rs.getString("address1")); if (address1 == null) address1 = "";
Solution
String address1 = HtmlUtil.escape(rs.getString("address1"));
String address1 = HtmlUtil.escape(rs.getString("address1")); if (address1 == null || address1.equals("null")) { address1 = ""; }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码