将结果集移动到第一个
我有一个结果集对象作为 rs,我使用代码片段来计算行数..
while(rs.next())
count++;
并且我必须再次使用相同的结果集来检索数据。我使用了该方法
rs.beforefirst();
,但它不起作用...控制未进入
while(rs.next()){
cid=rs.getInt(1);
taskdate=rs.getString(2);
tasktime=rs.getString(3);
addr=rs.getString(4);
}
我必须根据我的查询返回 4 行..但它没有???
I have a resultset obejct as rs and i used the fragment of code to count the number of rows..
while(rs.next())
count++;
and i has to use the same resultset again to retrieve the data. I used the method
rs.beforefirst();
but it is not working... control is not entering into
while(rs.next()){
cid=rs.getInt(1);
taskdate=rs.getString(2);
tasktime=rs.getString(3);
addr=rs.getString(4);
}
I has to return 4 rows according to my query.. but it doesn't ???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Resultset 仅是转发。如果您想导航回第一条记录,则需要创建可滚动结果集。
Resultset is the forward only . If you want to navigate back to the first record you need to create scrollable resultset .
检查是否
ResultSet
的类型为TYPE_FORWARD_ONLY
- 那么对beforefirst
的调用将不起作用(根据它在此抛出的文档)案例)。Check if the
ResultSet
is of typeTYPE_FORWARD_ONLY
- then the call tobeforefirst
wouldn't work (according to the docs it throws in this case).