Java: Detecting a null value in a double column

Hi,

I have a database table (where number is a double(10,2) column)

ID |  number
1   |  456.98
2   |  874.99
3   |  765.98
4   |  NULL
5   |  879.98

to get a number of use

recordset.getDouble("number");

but how do I detect the null value?

i.e.

if number is null {
 // the number is null
} else {
 the number isn't null
}


Thanks
J
JamesFrogAsked:
Who is Participating?
 
objectsCommented:
recordset.getDouble("number");
if (recordset.wasNull()) {
    // null
}

0
 
CEHJCommented:
Try the following first
Object o = rs.getObject(doubleCol);
if (o == null) {
    // etc
}

Open in new window

0
 
objectsCommented:
you'd of course assign the value returned by getDouble to a var if you needed it.

0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
JamesFrogAuthor Commented:
... my ACTUAL code is as here - so I'm trying to get it NOT to set highestHigh when the PriceHigh in the table is a NULL value
if ((resultset.getDouble("PriceHigh")>highestHigh)&&(resultset.getDouble("PriceHigh").!equals("NULL"))){
   								highestHigh = resultset.getDouble("PriceHigh");
   							}

Open in new window

0
 
objectsCommented:
you need to pull them as var before the if

double highprice = resultset.getDouble("PriceHigh");
if (recordset.wasNull()) {
    // null
} else {

0
 
JamesFrogAuthor Commented:
Thanks, that works perfectly: final code that works is

if (resultset.getDouble("PriceHigh")>highestHigh){
                                            if (resultset.wasNull()) {
                                               // null
                                                  }else{
                                                   highestHigh = resultset.getDouble("PriceHigh");}
                                             }
                                             
                                             if (resultset.getDouble("PriceLow")
0
 
CEHJCommented:
Why don't you just select and order by price btw?
0
 
JamesFrogAuthor Commented:
Because I need the null values in the recordset to signal other aspects of what is going on here (like week-ends and bank holidays) and detection of last trading day of any particular week.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.