views:

65

answers:

2

I am extracting values from a database. I am extracting a double value from a database using

ResultSet rs = ....;
while(...){
  rs.getDouble("num");
}

How do I check if the value of rs.getDouble("num") is a null. Since the value is stored as a (MySQL) double and I want to store it in my JVM as a double, I can't simply use !=null.

What is the easiest way. Would converting the value to a Double() and then doing .equals(null) be the easiest/best (in your opinion) way?

+7  A: 

Test rs.wasNull() after the rs.getDouble().

Justin K
A: 

So the javadoc says it returns 0 if it was null. So what you need to do is call wasNull() (on the result set) if the value was 0; then you'll know if it was really 0 or null.

danpaq