本文介绍了如何从结果集中获取Double而不是double?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用JDBC结果集时,我希望得到Double而不是double,因为此列可以为空。当列为空时,Rs.getDouble返回0.0。
When working with a JDBC resultset I want to get Double instead of double since this column is nullable. Rs.getDouble returns 0.0 when the column is null.
推荐答案您可以检查 wasNull 在ResultSet上查找值是否为 null 。
请注意您必须首先调用列上的其中一个getter方法以尝试读取其值,然后调用方法wasNull以查看读取的值是否为SQL NULL。
Note that you must first call one of the getter methods on a column to try to read its value and then call the method wasNull to see if the value read was SQL NULL.
如果你之后确实需要一个 Double ,你可以从返回 double 。
If you really need a Double afterwards, you can create it from the double returned.
更多推荐
如何从结果集中获取Double而不是double?
发布评论