my dog learned polymorphism*
The moose likes JDBC 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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "null object in result sets" Watch "null object in result sets" New topic
Author

null object in result sets

jonathan mozes
Greenhorn

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 ...
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

Joined: Feb 26, 2001
Posts: 12
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

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.
your
JonathanM
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: null object in result sets
 
Similar Threads
Strings
struts form beans
printing default value of char
Java Object assignment doubt.
next line in swings