Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking if double is null

Status
Not open for further replies.

bunnyweb

MIS
Jan 13, 2003
42
IE
I'm having a problem. I am reading a double value out of my database like so:

double VisitDate = rsReport.getDouble("VisitDate");

My database allows nulls values so I want to check if this value is null. I tried quite a few things, but keep getting error messages.

I remember something I saw once about needing to convert this to a Double data type in order to check for a null value. So I tried:

double VisitDateCheck = Double.valueOf(VisitDate).doubleValue();

But I got an error message there as well.

If I first make my VisitDate variable a string and then use the Double data type that seems to work. However, I find it hard to believe that I have to take a double, cast it to a string, and then back to a double just to check if the value is null.

What am I doing wrong?? Thanks in advance for any and all help!
 
You cannot check if a primitive type like double is null, null can only be asigned to objects.

You need to check which error values can return your rsReport.getDouble() method.

Cheers.

Dian
 
As has been said, primitive values can not be equal to null, as they're not objects. You'll want to determine what exactly rsReport.getDouble() will return when it attempts to return a null value from the DB (hopefully this is documented, or at least it should be). Hopefully, it will return something like Double.NaN, which is much easier to test against than something like 0. If you are also in charge of the rsReport, you might want to make this the case.<BR><BR>What error messages are you getting? <p>Liam Morley<br><A HREF="mailto:"></A><br>&quot;light the deep, and bring silence to the world.<br>light the world, and bring depth to the silence.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top