How to check for null value for a double which is taken from a database

亡梦爱人 提交于 2019-12-07 17:31:32

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/3558585/how-to-check-for-null-value-for-a-double-which-is-taken-from-a-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!