This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes problem in returning data using resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem in returning data using resultset" Watch "problem in returning data using resultset" New topic
Author

problem in returning data using resultset

sahar sa
Ranch Hand

Joined: Jul 06, 2009
Posts: 102
Dear,
Im trying to retrive some information using select query and then pass the result set to another program. While running i got the error saying that the resultset is closed and can not have access. so I cleaned any pstmt.close or con.close . But still it throws me the same error. Do you know where is the problem? Here i copy the SELEC and TRIGGER classes and the error.
////////////Select///////////


//////// a piece of trigger class///////


////////////and here is the error/////////

java.sql.SQLException: Operation not allowed after ResultSet closed
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)

Do you know how can i solve it?
Thank you so much,
Sahar.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3817

Hi sahar sa,

Can you please format the code using "code" tags (you can do it by editing your post just put the code inside "[code]" tags). Unformatted code is very hard to read.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
sahar sa
Ranch Hand

Joined: Jul 06, 2009
Posts: 102
thanks for your explanation, I think now is formatted?! ;)
sahar sa
Ranch Hand

Joined: Jul 06, 2009
Posts: 102
Dear friends!
any idead about this error please?

thnx,
Sahar.
vikram Kesav
Ranch Hand

Joined: Jul 11, 2008
Posts: 69
Read this -
"A ResultSet object is automatically closed when the Statement object that generated it is closed, re-executed, or used to retrieve the next result from a sequence of multiple results."

sahar sa
Ranch Hand

Joined: Jul 06, 2009
Posts: 102
Dear,
But I did'nt close any statement or connection and I did'nt re-execute it (you can check the code above!)
So remains third option "retriving next result from a sequence of multiple result". I searched many about this but I'm still confuse that a simple select does have a sequence of multiple result. I think no!
1) Am I right?
2) If Im right what is wrong then?

thank you so much!
Sahar.
vikram Kesav
Ranch Hand

Joined: Jul 11, 2008
Posts: 69
Are you sure that something somewhere (your connection pool, for example) isn't executing
another query on the given statement? _Something_ is closing that result set, either it's
explicitly closed, or it's being closed by the fact that the statement has either had
another query executed on it, or the statement itself has been closed, either explicitly
or by the Connection that created it being closed.

See everytime you execute the statement, all open resultsets will be closed. There is no way around that.

So, you will have to read the entire resultset and save the results, then loop through those results, setting of the query again for the "next level down/up" and, once again, reading in the entire result set etc.

Else, you need to create a new statement object instead of PrepareStatement.
 
Consider Paul's rocket mass heater.
 
subject: problem in returning data using resultset
 
Similar Threads
select .... where... query for a variable?
reasons for error: SQLException: No operations allowed after connection closed?
closing connection?
can not insert to DB after a while!
how can I have multiple return from this method?