Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting an error with addressing query

 
Kenneth Lin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

let me start off with the code, which show nothing wrong at the query side but when i call out the rs.getString("id"), it gives me invalid cursor state




this what the query looks like and what it supposed to show on the access side.



any idea what i did wrong? and why it says invalid cursor state when im not referring/doing 2 connections.

thanks

[JB: fixed line wrapping]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What line gives "invalid cursor state"? Also, is it safe to assume that is happening on the first line through the loop.

ps - I edited your post so the SQL line doesn't cause the screen so scroll.
 
Paul Clapham
Sheriff
Posts: 21576
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One minor thing, not related to the question you asked. The API documentation for Statement's executeQuery() method says this:

Returns:
a ResultSet object that contains the data produced by the given query; never null


That means you don't have to check whether rs is null. So don't do that; code which has no purpose is just a nuisance.
 
Kenneth Lin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:What line gives "invalid cursor state"? Also, is it safe to assume that is happening on the first line through the loop.

ps - I edited your post so the SQL line doesn't cause the screen so scroll.


here's the exact error code

org.apache.jasper.JasperException: An exception occurred processing JSP page /forum.jsp at line 106

103: {
104: while(rs.next())
105: {
106: out.print(rs.getString("ThreadName"));
107: }
108: }
109:


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
root cause

javax.servlet.ServletException: java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
 
Kenneth Lin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:One minor thing, not related to the question you asked. The API documentation for Statement's executeQuery() method says this:

Returns:
a ResultSet object that contains the data produced by the given query; never null


That means you don't have to check whether rs is null. So don't do that; code which has no purpose is just a nuisance.


carefully noted :)

thanks Paul!
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use ODBC. The Java implementation is known to be buggy and will be desupported in Java 8.

It looks like you're using an MS Access database for a web application. I'd say this is not a good idea too; firstly it makes you use ODBC (see previous point), and secondly, MS Access is not known for its stability, especially in multiuser environment. Practically any open source database, such as Derby or MySQL, can be used instead of MS Access.

The error you're encountering could be connected to the ODBC driver actually. Some drivers might require you to read every column from a resultset at most once, and also to read them in the exact order they are present in the resultset. You're retrieving column ThreadName (in the code you've posted), but the first column in the resultset is Id. This might be a problem for an ODBC driver.
 
Kenneth Lin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys found a hope here, i think the error is because its trying to show of something thats not there (null), when i tried to count the row using


suprisingly it returns 4 when theres only 3 data to return to. still dont get it why it shows 4 when its only 3 to return hmmm
 
Paul Clapham
Sheriff
Posts: 21576
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, that's another funny thing that MS Access does when you ask it to join two tables sometimes. I join the others in recommending that you don't use it.
 
Kenneth Lin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahh now i see why its 4, because its running 4 data.

so


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic