如何从结果集中获取Double而不是double?

编程入门 行业动态 更新时间:2024-10-08 10:49:05
本文介绍了如何从结果集中获取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?

本文发布于:2023-11-29 15:46:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646840.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:而不是   Double   double

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!