无效的游标状态JSP到Access DB

时间:2013-12-28 07:30:29

标签: java jsp

<%  String qTotal = "SELECT MsThread.ID,MsThread.ThreadName, Count(MsThread.ThreadName) AS TotalPost, ThreadCategory FROM MsThread LEFT OUTER JOIN MsPosts ON MsThread.ThreadName = MsPosts.ThreadName GROUP BY MsThread.ID, MsThread.ThreadName, MsThread.ThreadCategory;";

                ResultSet rs = st.executeQuery(qTotal);
                ResultSet rs1 = stmt.executeQuery(qTotal);
                while(rs.next())
                {
                    String idThread = rs.getString("id");
                %>                              
                        <tr>
                          <td><img src="f-img/def.png" width="50px" height"50px"/></td>
                          <td><a href="thread.jsp?id=<%=idThread%>"><%=rs.getString("ThreadName")%></a></td>
                          <td><%=rs.getString("TotalPost")%> posts
                          </td>
                          <td>Lala</td>
                        </tr>
                        </div>
                        <br /> <br />            
              <% 
            }
      %>

这是我尝试将数据库连接到JSP,目前正在显示

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

我只编辑了整个代码。我希望你能理解我想要展示的内容,如果需要更多细节,请告诉我。 谢谢你的帮助

2 个答案:

答案 0 :(得分:0)

首先,你有

ResultSet rs = st.executeQuery(qTotal);
ResultSet rs1 = stmt.executeQuery(qTotal);

为什么有两个你没有提到的结果集,看起来你没有写完整个循环。

您的代码应该像

if(rs != null){
while(rs.next()){
System.out.println(rs.getString('field'));
}
}

答案 1 :(得分:0)

从你的代码中我没有想到它中的任何错误。可能你在while循环中遗漏了一些代码,就像你的while循环中从未使用的ResultSet rs1一样。

但根据您的错误,我预测会出现以下错误。

There error message Invalid Cursor State indicates that you are trying to access 
the current row's data when in fact the result set is position before the start  
or after the end of the result set.