• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Accessing Return Code Closes RecordSet?

 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm invoking a stored procedure (in SQL 2000) from a Java application. That stored procedure returns a return code and a result set. My code looks something like this:



If I execute this code as is, I get an error at the line "while ( rs.next() )". My stack dump reads that the ResultSet is closed.

To test, I removed the if check so that I no longer check the return code and my code executes just fine. So, it would appear that checking the return code closes the ResultSet. Why? Is there any way to check it without closing the ResultSet?

Thanks,
Corey
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I remember reading that we have to maintain the order in a specific way

like
rs = cstmt.executeQuery()
process the result set while(rs.next()) {

}
// out parameter
cstmt.getInt(1)
 
Napa Sreedhar
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am really unsure why the result set is getting closed.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Napa Sreedhar:
I remember reading that we have to maintain the order in a specific way

like
rs = cstmt.executeQuery()
process the result set while(rs.next()) {

}
// out parameter
cstmt.getInt(1)



I think something like that would function, but it really doesn't work for what I want to do. I want to first check the return code to ensure that there is valid data in the result set. If the return code shows an error condition, I don't want to do the processing.
 
author & internet detective
Posts: 40198
816
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Corey,
Can you just copy the data into a data structure and process it later (after knowing the error code? I think this would work unless you are dealing with very large data sets, like we do. Even copying thousands of records is doable.
 
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Corey,

This is from the Javadocs for Callable Statement -


For maximum portability, a call's ResultSet objects and update counts should be processed prior to getting the values of output parameters.



This is probabely the cause of your problem.

Cheers
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Jeanne Boyarsky:
Corey,
Can you just copy the data into a data structure and process it later (after knowing the error code? I think this would work unless you are dealing with very large data sets, like we do. Even copying thousands of records is doable.



Jeanne,

That ended up being my workaround. I put all the information into a data structure and, when I was done, I checked the return code. If it was an error code, I simply set my data structure to null, destroying anything I had put in there previously. Apparently, that may be the way to go.

Thanks for the update, Sonny.
 
The only cure for that is hours of television radiation. 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
    Bookmark Topic Watch Topic
  • New Topic