Reading Multiple Reult Set from Stored Procedues

I am reading multiple resul sets(10+) from a stored procedure, My question is if its done in one round trip to sql server or multiple trips are involved.

thanks
Sunil
sunilramuAsked:
Who is Participating?
 
RuadRauFlessaConnect With a Mentor Commented:
sunilramu did you properly read what I have written. I stated that a normal resultser needs to buffer the data in certain block sizes and that is for the purpose of memory concervation since you don't want it to potentially buffer over 100,000 records on your local machine especialy if that local machine is a normal workstation. I also stated that the buffering has an even bigger effect when using a scrollable resultset. I didn't say that it is only with scrollable resultsets that you have this buffering issue that is needed but that it needs to maintain the buffers in a more agressive manner. With any network communication you will always have more than one round trip since some data may be lost between the transmissions and such. The thing is however that by using the TCP protocol you won't have need to retrieve the same data twice. And if you are referring to round trips for the same data then I would say stick to a non-scrollable resultset.
0
 
sudhakar_koundinyaCommented:
AFAIK,

It is not possible
0
 
sunilramuAuthor Commented:
it is possible to read multiple result sets using execute method rather than executeQuery
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
sunilramuAuthor Commented:
I am reading multiple result sets fine, but i need to know how many round trips to the sever are involved.
0
 
sudhakar_koundinyaCommented:
>>it is possible to read multiple result sets using execute method rather than executeQuery

Yeah That's true.




With certain database systems, a stored procedure can return multiple result sets, multiple update counts, or some combination of both. Also, if you are providing a user with the ability to enter any SQL statement, you don't know if you are going to get a ResultSet or an update count back from each statement, without analyzing the contents. The Statement.execute() method helps in these cases.

Method Statement.execute() returns a boolean to tell you the type of response:

    * true indicates next result is a ResultSet
      Use Statement.getResultSet to get the ResultSet
    * false indicates next result is an update count
      Use Statement.getUpdateCount to get the update count
    * false also indicates no more results
      Update count is -1 when no more results (usually 0 or positive)

After processing each response, you use Statement.getMoreResults to check for more results, again returning a boolean. The following demonstrates the processing of multiple result sets:

boolean result = stmt.execute(" ... ");
int updateCount = stmt.getUpdateCount();

while (result || (updateCount != -1)) {
  if(result) {
    ResultSet r = stmt.getResultSet();
    // process result set
  } else if(updateCount != -1) {
    // process update count
  }
  result = stmt.getMoreResults();
  updateCount = stmt.getUpdateCount();
}

0
 
sudhakar_koundinyaCommented:
0
 
sudhakar_koundinyaCommented:
>>My question is if its done in one round trip to sql server or multiple trips are involved.

>>am reading multiple result sets fine, but i need to know how many round trips to the sever are involved.


OK. Now I understand the question. Ignore all previous comments
0
 
CEHJCommented:
This would probably be implemented by the driver returning a list of pointers to n cursors. To fetch the data, you would access each pointer via the CallableStatement and get the data from the server
0
 
objectsCommented:
The number of round trips is dependant on the driver, even with a single result set there may be more than one round trip.
0
 
RuadRauFlessaCommented:
Objects and CEHJ is corrent. Your driver basically retrieves and cashes a certain ammount of results if that many is available at the time and as you read through the resultset it looks at where you are and determines if it is needed for it to fetch any more. This would make scrollable resultsets more resource intensive and possibly even much slower since it would have to take into account that it should retrieve overlapping sets of data because you can scroll back one when it has just fetched the new data and then it would have to fetch the whole previous block again. This is unfortuantely a hassle and a bogdown on the way that database drivers has to operate.

Just of interest when you open a file the same basically happens within the OS as well. Reading blocks at a time while you only read subsets of that block. That is also why it is advised to open  file in a strict manner as to what you need to do with it.
0
 
sunilramuAuthor Commented:
Can I make my statement as forword only, so that driver can use this information and know that there is no scrolling back?
0
 
CEHJCommented:
The default is forward only
0
 
objectsCommented:
> Can I make my statement as forword only, so that driver can use this information and know that
> there is no scrolling back?

there could still be more than one round trip.

If you're concerned about performance try adjust the fetch size for the result set using setFetchSize()

0
 
RuadRauFlessaCommented:
Sunilramu: Glad to be of service.
0
All Courses

From novice to tech pro — start learning today.