I have an application using four threads. In each of the 4 threads, an SP is called which returns a resultset. When i use this result set it returns an SQL exception saying that the resultset is closed.
In the code, Once I complete the process i give Thread.yield(). But still it is giving me a problem. I am not explicitly closing the resultset anywhere. What am I supposed to do???
It is possible that you are closing the Statement that produced the ResultSet. Or it is possible that you are reusing it to produce another ResultSet. Either of those two things would cause your problem. I am sure there are other ways to do it, too.
Why are the statement and the result set static fields?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
If you are using one statement instance for all Threads ,whenever you execute the statement, you close automatically the previous ResultSet which it holds on it.Because a statment instance can hold only one ResultSet. Reexecuting same statement will interrupt (close) the previous resultset. [ July 01, 2006: Message edited by: sinasi susam ]
posted 14 years ago
Hi Naresh, As Ilja Preuss pointed out, why you have declared connection, resultset etc. as static variable. When there will be more than one thread executing your method, then there will be a race condition between the thread.
You should not declare resultset, connection, callablestatament as global things neither static nor instance.
I have made some changes to your code. Try this in place of yours.