Solved

Reading Multiple Reult Set from Stored Procedues

Posted on 2004-10-13
16
169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues undeā€¦
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilationā€¦
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.
Suggested Courses

752 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