Solved

Reading Multiple Reult Set from Stored Procedues

Posted on 2004-10-13
16
166 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:sunilramu
  • 6
  • 3
  • 3
  • +2
16 Comments
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12301139
AFAIK,

It is not possible
0
 

Author Comment

by:sunilramu
ID: 12301156
it is possible to read multiple result sets using execute method rather than executeQuery
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12301170
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12301234
0
 

Author Comment

by:sunilramu
ID: 12301237
I am reading multiple result sets fine, but i need to know how many round trips to the sever are involved.
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12301265
>>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
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12301281
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12301305
>>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
 
LVL 86

Expert Comment

by:CEHJ
ID: 12302422
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
 
LVL 92

Expert Comment

by:objects
ID: 12303450
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
 
LVL 3

Expert Comment

by:RuadRauFlessa
ID: 12305833
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
 

Author Comment

by:sunilramu
ID: 12307842
Can I make my statement as forword only, so that driver can use this information and know that there is no scrolling back?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12311735
The default is forward only
0
 
LVL 92

Expert Comment

by:objects
ID: 12312784
> 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
 
LVL 3

Accepted Solution

by:
RuadRauFlessa earned 500 total points
ID: 12316339
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
 
LVL 3

Expert Comment

by:RuadRauFlessa
ID: 12641648
Sunilramu: Glad to be of service.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 108
SHA2 certs for IIS AND Java? 2 91
Desingning Refactoring existing code 2 24
Java Restore security prompts not working 10 13
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question