com.microsoft.sqlserver.jdbc.SQLServerException:结果集没有当前行 [英] com.microsoft.sqlserver.jdbc.SQLServerException: The result set has no current row

查看:414
本文介绍了com.microsoft.sqlserver.jdbc.SQLServerException:结果集没有当前行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取结果集第一行中的第一列.我知道我可以更改SQL查询来做到这一点.但不是.我想要一张完整的桌子,我只想做我刚才提到的事情.

I am trying to get the first column in the first row of my result set. I know I can change my SQL query to do that. BUT no. I want the full table and I only want to do what I just mentioned.

注意-优胜者是我的sql查询中的别名列.

错误基本上是-

com.microsoft.sqlserver.jdbc.SQLServerException: 
The result set has no current row.

更多错误-

at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.verifyResultSetHasCurrentRow(SQLServerResultSet.java:483)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getterGetColumn(SQLServerResultSet.java:2047)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getValue(SQLServerResultSet.java:2082)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getValue(SQLServerResultSet.java:2067)
at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getString(SQLServerResultSet.java:2401) 

这是我到目前为止已经尝试过的,我需要您的帮助来解决-

This is what I have tried so far and I need your help to fix it -

ResultSet rs = statement.executeQuery("get a whole table"); //pseudocode

try{            
    rs.next();
    numberOne = rs.getString("Winners");
    rs.first(); 
} catch (SQLException e) {
    e.printStackTrace();
}

推荐答案

结果集中可能没有任何内容.使用

There is probably nothing in your result set. Use

if (rs.next()) {
    numberOne = rs.getString("Winners");
}

这篇关于com.microsoft.sqlserver.jdbc.SQLServerException:结果集没有当前行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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