How to check for null value for a double which is taken from a database
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?
Test rs.wasNull() after the rs.getDouble().
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.
精彩评论