java com.microsoft.sqlserver.jdbc.SQLServerException: 结果集没有当前行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16801986/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
com.microsoft.sqlserver.jdbc.SQLServerException: The result set has no current row
提问by Apple Grinder
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 查询来做到这一点。但不是。我想要完整的表格,我只想做我刚刚提到的事情。
NOTE - Winners is an Aliased column in my sql query.
注意 - 获胜者是我的 sql 查询中的别名列。
The error is basically -
错误基本上是 -
com.microsoft.sqlserver.jdbc.SQLServerException:
The result set has no current row.
More of the error -
更多的错误 -
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();
}
回答by JB Nizet
There is probably nothing in your result set. Use
您的结果集中可能没有任何内容。利用
if (rs.next()) {
numberOne = rs.getString("Winners");
}