Reputation: 1
Edit: Subsequent checking of addrline2 (addrline2 == null) reveals that addrline2 is in fact null, printing out the null object resulting in the string "null" going to stdout.
I'm using the Oracle 11g thin client with an Oracle 11g database. When querying a column that contains null, getString("colname") is return a string "null" instead of a Java null value. Is that the expected behavior? Javadoc indicates I should be receiving a Java null.
ResultSet rs = descStatement.executeQuery();
rs.next();
String addrline2 = rs.getString("addressLine2");
System.out.println("addrLine2->"+addrline2+"<-");
boolean wasNull = rs.wasNull();
System.out.println("Wasnull: "+wasNull);
output:
addrLine2->null<-
Wasnull: true
Upvotes: 0
Views: 6746
Reputation: 34424
rs.getString("addressLine2") is returning null only but when yo do
System.out.println("addrLine2->"+addrline2+"<-");
its printing null as string literal
do it like this
System.out.println("addrLine2->"+addrline2!=null ? addrline2 : "Its null"+"<-");
Upvotes: 1
Reputation: 436
Note that a null object, when converting to a string, prints out as "null". You're not actually checking for null-ness anywhere.
Try adding
if (addrline2 == null) {
System.out.println("It's null!")
}
Upvotes: 7