Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

null object in result sets

 
jonathan mozes
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ...
output:
" Street : ";
if(rs.getStreet("STREET") == null)
//this returns false
if(rs.getStreet("STREET").equals("null"))
//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
else
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
jonathan





 
mujtaba habib
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!
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.
if(rs.wasNull())
System.out.println("No Address");
 
jonathan mozes
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
your
JonathanM
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic