This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes null object in result sets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "null object in result sets" Watch "null object in result sets" New topic

null object in result sets

jonathan mozes

Joined: Jan 21, 2001
Posts: 13

hey everyone ,
i have a simple question about result in a result set that
gives back null ,
if my code looks like this :
System.out.println("Street : " + rs.getString("STREET"));
output (it actually writes 'null'):
" Street : null ";
i don't want it to happen , i wish to it like this ...
" Street : ";
if(rs.getStreet("STREET") == null)
//this returns false
//of course.. NullPointerException
if(rs.getStreet("STREET") != null)
//returns false too.
i can only do something like this :
String str = rs.getString("STREET");
if(str != null)
System.out.println("Street : " + str)
// OK
System.out.println("Street : ")
which cause the code to run very slow ... and resources are low ,
is there a way to compare a rs.getString("STREET") (or ay other type)
to NULL... ! :-)
thanks a lot

mujtaba habib

Joined: Feb 26, 2001
Posts: 12
ResultSet interface provides a method for testing column values within a result set to determine if it is null. The wasNull() method returns true if the last col read from the ResultSet object was null.
System.out.println("No Address");
jonathan mozes

Joined: Jan 21, 2001
Posts: 13
thank you , but i don't wish to invoke wasNull()
cause it's being called after the value retrived , i wish to test the value when i invoke getXXX method.
I agree. Here's the link:
subject: null object in result sets
It's not a secret anymore!