如何从结果集中获取Double而不是double? [英] How do I get a Double out of a resultset instead of double?

查看:92
本文介绍了如何从结果集中获取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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆