【问题标题】:[Microsoft][ODBC Driver Manager] Invalid cursor state[Microsoft][ODBC Driver Manager] 游标状态无效
【发布时间】:2014-01-15 04:08:26
【问题描述】:

伙计们,这就是我所拥有的。当前的错误是

javax.servlet.ServletException: java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state

这是导致错误的工作

String query3 = "SELECT Last(threadID) AS thread2 FROM msthread";
ResultSet rs = stmt.executeQuery(query3); 
rs.getString("thread2");

该查询的结果只是返回 1 列和 1 行,通过 MSAccess 运行它,它完全显示了我想要看到的内容。

This is exactly what it looks like:    
thread2
43

但现在我不断收到 Invalid Cursor State 错误。我不知道为什么。

感谢大家的帮助

【问题讨论】:

标签: java sql ms-access jdbc jdbc-odbc


【解决方案1】:

您需要在ResultSet 上调用next(),然后才能检索值。

所以使用:

if (rs.next()) {
    rs.getString("thread2");
}

(或while 循环)

【讨论】:

  • 正确答案。有关详细信息,请参阅 JavaDoc:A ResultSet object maintains a cursor pointing to its current row of data. Initially the cursor is positioned before the first row. etc.
猜你喜欢
  • 2023-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-19
相关资源
最近更新 更多