Solved

Reading Multiple Reult Set from Stored Procedues

Posted on 2004-10-13
16
163 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now