• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing Return Code Closes RecordSet?

 
Corey McGlone
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
 
Napa Sreedhar
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • 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.
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic