Arun :
I remember runnig into the same problem, and solving the same...
I hope I still remember the soln
Try the following:
bring the st2 initialization statement inside the loop it would work!
I mean the following line to inside the while loop, and just before calling st2.executeQuery.
The javadoc clearly states that one-instance-of-statement-can-be-used-only-once
=====================
"Only one ResultSet object per Statement object can be open at any point in time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects. All statement execute methods implicitly close a statment's current ResultSet object if an open one exists.
=====================
"
Statement st2 = conn.createStatement();
Please let me know if this was helpful and worked.