This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Processing of Multiple Resultset Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Processing of Multiple Resultset" Watch "Processing of Multiple Resultset" New topic
Author

Processing of Multiple Resultset

Dibya G. Baruah
Greenhorn

Joined: Aug 08, 2002
Posts: 4
I have three resultsets which needs to be processed in while loop. The code is like this:
//Statement stmt1 = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt1.executeQuery(reportQuery1);
ResultSet rs2 = stmt1.executeQuery(reportQuery2);
ResultSet rs3 = stmt1.executeQuery(reportQuery3);
while (rs.next()){
rs2.first();
while (rs2.next(){
/// Pocessing
}
}
if the 'rs' is empty then it is giving me null pointer exception in the first while loop.My understanding is that even if the resultset(rs) is empty it should not give me null pointer exception. Please advice.
Pat Wallwork
Ranch Hand

Joined: Sep 23, 2001
Posts: 72
For each ResultSet you need to specify a separate Statement. This is right in the API...

By default, only one ResultSet object per Statement object can be open at the same 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 execution methods in the Statement interface implicitly close a statment's current ResultSet object if an open one exists.

hth,
-Pat
 
jQuery in Action, 2nd edition
 
subject: Processing of Multiple Resultset
 
Similar Threads
ResultSet Thru ResultSet
multiple processes... only want one
Retrive 4000 more records
stored procedures in a loop... what gives?
How To Solve : java.sql.SQLException: Exhausted Resultset