Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Cursor state not valid

 
Ranch Hand
Posts: 2131
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cannot figure out why this code is generating message Cursor state not valid.

 
Ranch Hand
Posts: 78
1
Android Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does 'new SquawkSourceDetail(rs)' do with the result set? Further, it would be useful posting the full stacktrace of the exception.
 
Steve Dyke
Ranch Hand
Posts: 2131
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roland Mueller wrote:What does 'new SquawkSourceDetail(rs)' do with the result set? Further, it would be useful posting the full stacktrace of the exception.





Stack Trace:

[12/21/21 9:01:01:500 CST] 0000078e SystemErr     R java.sql.SQLException: Cursor state not valid.
[12/21/21 9:01:03:131 CST] 0000078e SystemErr     R at com.ibm.as400.access.JDError.createSQLExceptionSubClass(JDError.java:917)
[12/21/21 9:01:03:131 CST] 0000078e SystemErr     R at com.ibm.as400.access.JDError.throwSQLException(JDError.java:435)
[12/21/21 9:01:03:131 CST] 0000078e SystemErr     R at com.ibm.as400.access.JDError.throwSQLException(JDError.java:412)
[12/21/21 9:01:03:131 CST] 0000078e SystemErr     R at com.ibm.as400.access.AS400JDBCStatement.executeQuery(AS400JDBCStatement.java:2524)
[12/21/21 9:01:03:138 CST] 0000078e SystemErr     R at com.ibm.ws.rsadapter.jdbc.WSJdbcStatement.pmiExecuteQuery(WSJdbcStatement.java:1728)
[12/21/21 9:01:03:148 CST] 0000078e SystemErr     R at com.ibm.ws.rsadapter.jdbc.WSJdbcStatement.executeQuery(WSJdbcStatement.java:1019)
[12/21/21 9:01:03:148 CST] 0000078e SystemErr     R at com.FAIWebApp._application._datarepository._application.ApplicationSupportDataRepository.squawkSourceListResults(ApplicationSupportDataRepository.java:7424)
[12/21/21 9:01:03:148 CST] 0000078e SystemErr     R at com.FAIWebApp._initialize.logonconnections.logon.LogOn.<init>(LogOn.java:150)
[12/21/21 9:01:03:148 CST] 0000078e SystemErr     R at com.FAIWebApp._initialize.controllers.LogonControllerServlet.doPost(LogonControllerServlet.java:145)
[12/21/21 9:01:03:148 CST] 0000078e SystemErr     R at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)
[12/21/21 9:01:03:148 CST] 0000078e SystemErr     R at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
[12/21/21 9:01:03:148 CST] 0000078e SystemErr     R at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1232)
[12/21/21 9:01:03:148 CST] 0000078e SystemErr     R at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:781)
[12/21/21 9:01:03:149 CST] 0000078e SystemErr     R at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:480)
[12/21/21 9:01:03:149 CST] 0000078e SystemErr     R at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
[12/21/21 9:01:03:149 CST] 0000078e SystemErr     R at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:136)
[12/21/21 9:01:03:149 CST] 0000078e SystemErr     R at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:97)
[12/21/21 9:01:03:149 CST] 0000078e SystemErr     R at com.FAIWebApp._application._qms.QMSFilterImproved.doFilter(QMSFilterImproved.java:143)
[12/21/21 9:01:03:149 CST] 0000078e SystemErr     R at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
[12/21/21 9:01:03:149 CST] 0000078e SystemErr     R at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
[12/21/21 9:01:03:149 CST] 0000078e SystemErr     R at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:967)
[12/21/21 9:01:03:149 CST] 0000078e SystemErr     R at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1107)
[12/21/21 9:01:03:149 CST] 0000078e SystemErr     R at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
[12/21/21 9:01:03:149 CST] 0000078e SystemErr     R at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:947)
[12/21/21 9:01:03:149 CST] 0000078e SystemErr     R at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1817)
[12/21/21 9:01:03:149 CST] 0000078e SystemErr     R at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200)
[12/21/21 9:01:03:149 CST] 0000078e SystemErr     R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:463)
[12/21/21 9:01:03:149 CST] 0000078e SystemErr     R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:530)
[12/21/21 9:01:03:150 CST] 0000078e SystemErr     R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:316)
[12/21/21 9:01:03:150 CST] 0000078e SystemErr     R at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:88)
[12/21/21 9:01:03:150 CST] 0000078e SystemErr     R at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:558)
[12/21/21 9:01:03:150 CST] 0000078e SystemErr     R at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java:608)
[12/21/21 9:01:03:150 CST] 0000078e SystemErr     R at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:985)
[12/21/21 9:01:03:150 CST] 0000078e SystemErr     R at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1074)
[12/21/21 9:01:03:150 CST] 0000078e SystemErr     R at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1892)
 
Steve Dyke
Ranch Hand
Posts: 2131
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roland Mueller wrote:What does 'new SquawkSourceDetail(rs)' do with the result set? Further, it would be useful posting the full stacktrace of the exception.



Sorry posted wrong code:

 
Steve Dyke
Ranch Hand
Posts: 2131
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roland Mueller wrote:What does 'new SquawkSourceDetail(rs)' do with the result set? Further, it would be useful posting the full stacktrace of the exception.



Stack Trace points to line 14 in initial code post.
 
Saloon Keeper
Posts: 24826
172
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need to wrap every field fetch with a try-catch block. One block is good enough for all, assuming you're fetching properly.

Cursor invalid state usually means that the cursor has been closed or is at a position that is not valid to read from (like when rs.next() has returned false.
 
Roland Mueller
Ranch Hand
Posts: 78
1
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Dyke wrote:

Roland Mueller wrote:What does 'new SquawkSourceDetail(rs)' do with the result set? Further, it would be useful posting the full stacktrace of the exception.



Stack Trace points to line 14 in initial code post.



I was expecting that the constructor of SquawkSourceDetail would do something that causes the invalid cursor. However, from perspective of ResultSet handling I cannot see anything wrong.

Since the error happened already in line 14 it seams that the Statement stmt is not compatible with the kind of Statement returned from createStatement().

Jvadoc for java.sql.Statement#executeQuery gives some warning in case of incompatible Statement type or when return value is not a single ResultSet.



 
Steve Dyke
Ranch Hand
Posts: 2131
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roland Mueller wrote:

Since the error happened already in line 14 it seams that the Statement stmt is not compatible with the kind of Statement returned from createStatement().



Yes, however, it only generates the error sporadically.

The connection is linked to connection pool using jndi. Maybe the connection is dropping?
 
Tim Holloway
Saloon Keeper
Posts: 24826
172
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Dyke wrote:

Roland Mueller wrote:

Since the error happened already in line 14 it seams that the Statement stmt is not compatible with the kind of Statement returned from createStatement().



Yes, however, it only generates the error sporadically.

The connection is linked to connection pool using jndi. Maybe the connection is dropping?



If the connection is dead coming out of the pool, you need to configure the pool to prevent that (it does a test and creates fresh pool connections, discarding dead ones).

If the connection goes dead while checked out of the pool, you're not using it properly. You should obtain the connection only when you need it, return it as soon as possible and absolutely never hold one between HTTP request/response cycles.
 
Steve Dyke
Ranch Hand
Posts: 2131
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:

Steve Dyke wrote:

Roland Mueller wrote:

Since the error happened already in line 14 it seams that the Statement stmt is not compatible with the kind of Statement returned from createStatement().



Yes, however, it only generates the error sporadically.

The connection is linked to connection pool using jndi. Maybe the connection is dropping?



If the connection is dead coming out of the pool, you need to configure the pool to prevent that (it does a test and creates fresh pool connections, discarding dead ones).

If the connection goes dead while checked out of the pool, you're not using it properly. You should obtain the connection only when you need it, return it as soon as possible and absolutely never hold one between HTTP request/response cycles.



So my code does this, correct?

 
Tim Holloway
Saloon Keeper
Posts: 24826
172
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems OK to me, but it would be easier to read if you hadn't double-spaced it.

One thing, though. It's very bad practice to begin a Java property name with an upper-case letter as though it was a class. It can, in fact confuse some Java tools. It's EXTREMELY bad practice to make the entire name be upper-case, as that convention is used to indicate manifest constants.
 
Sheriff
Posts: 22568
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is SQL a field of this class? If so, why? You may have a race condition if the field is used in more than one place. If it's used as an UPDATE statement somewhere, then the following flow is possible:
  • This SELECT statement is assigned to SQL
  • The connection is initiated
  • In another thread, an UPDATE statement is assigned to SQL
  • The connection is finalized and the statement is created
  • The statement is executed with SQL which is now an UPDATE statement

  • My suggestion: turn the SQL field into a local variable (and name it sql or query). There's no reason to not use a local variable for it.
     
    Steve Dyke
    Ranch Hand
    Posts: 2131
    2
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Rob Spoor wrote:Is SQL a field of this class?



    Yes, very good observation. I was wandering if this might be the case.
    Thanks you.
     
    Rob Spoor
    Sheriff
    Posts: 22568
    122
    Eclipse IDE Spring VI Editor Chrome Java Windows
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Did changing it to a local variable fix the issue?
     
    Steve Dyke
    Ranch Hand
    Posts: 2131
    2
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Rob Spoor wrote:Did changing it to a local variable fix the issue?



    I have not redeployed the app yet.
    It never happened in my development environment.
    But in Production when 100+ users were accessing it was when the error occurred.
    It took a while to fix my code because I had used the SQL as a class field several thousand times.

    I will let you know but I am confident this was the culprit.
     
    Tim Holloway
    Saloon Keeper
    Posts: 24826
    172
    Android Eclipse IDE Tomcat Server Redhat Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    What bothers me about this is that this statement:


    Has the appearance of a manifest constant expression. The capitalization of AS400LibraryStringsV5 would imply that it's a class and the all-caps PRODUCTION should mean that it's a constant, with the context being that it's class-scope and therefore assumed immutable (final).

    In such cases, I would have coded this:


    And, incidentally, "SELECT *" is playing with fire anyway.

    But as you can see, either SQL definitions should not fix your problem, since it's not likely to be corrupted by threading issues. In fact, if it's a method-local constant, it can't be since it's on the method's call stack and not on any other thread's call of that method.

    However, the number of connections is another matter. Let me look at that…
     
    Tim Holloway
    Saloon Keeper
    Posts: 24826
    172
    Android Eclipse IDE Tomcat Server Redhat Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hmmm. You have a nested try and it doesn't catch anything. Looks like a lazy way to close Statement/ResultSet and I wouldn't recommend it.

    At 100+ Connections, the possibility exists that you're requesting more Connections from the pool than it can supply. One would assume that should you exceed capacity, the get Connection method would throw an Exception. But I'd check, because another possibility might be that it returns null.

    Also check the server logs. If a fault happens in the Connection Pool, it won't log directly with the application, since the Pool is owned by the server, not the application.
     
    You showed up just in time for the waffles! And this tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    reply
      Bookmark Topic Watch Topic
    • New Topic