在结果集中重复检索将返回null [英] Repeated retrieval in result set returns null

查看:87
本文介绍了在结果集中重复检索将返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ResultSet.getString时遇到问题,当我第一次调用它时,它返回值,但是第二次返回null(这没有关闭结果集或sql连接)

I'm having an issue with ResultSet.getString where when I call it the first time it returns the value but the second time returns null (this without closing the resultset or the sql connection)

if (rs.getString(i) == null) {
    properties.setProperty(metaData.getColumnLabel(i), "");
} else {
    properties.setProperty(metaData.getColumnLabel(i), rs.getString(i));
}

当然,该代码很容易修复,从而避免了第二次调用rs.getString()的问题,但是我想理解的是为什么如果第二次调用rs.getString()时第二次返回null,则返回null

of course the code is easily fixable to avoid the second call to rs.getString() but what I want to understand is why the second return null if the first one didn't

推荐答案

来自 Javadoc :

为了获得最大的可移植性,应按从左到右的顺序读取每一行中的结果集列,并且每一列只能读取一次.

For maximum portability, result set columns within each row should be read in left-to-right order, and each column should be read only once.

在后台,您正在消耗TCP流中的字节,因此不能两次检索相同的列值也就不足为奇了.

Under the hood, you are consuming bytes from a TCP stream, so it isn't too surprising that you can't retrieve the same column value twice.

这篇关于在结果集中重复检索将返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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