Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 650
  • Last Modified:

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
0
JamesFrog
Asked:
JamesFrog
  • 3
  • 3
  • 2
1 Solution
 
CEHJCommented:
Try the following first
Object o = rs.getObject(doubleCol);
if (o == null) {
    // etc
}

Open in new window

0
 
objectsCommented:
recordset.getDouble("number");
if (recordset.wasNull()) {
    // null
}

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

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now