Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Reading Multiple Reult Set from Stored Procedues

Posted on 2004-10-13
16
Medium Priority
?
173 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
Independent Software Vendors: 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!

 

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 1500 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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:
Suggested Courses

926 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