Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!fx06.iad.POSTED!not-for-mail From: Arved Sandstrom User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: JDBC: getMoreResults() versus rs.next() & autoGeneratedKeys References: <52b4dbf5$0$304$14726298@news.sunsite.dk> <1yltu.41101$TA.8682@fx09.iad> <52b5f45b$0$297$14726298@news.sunsite.dk> In-Reply-To: <52b5f45b$0$297$14726298@news.sunsite.dk> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Lines: 59 Message-ID: X-Complaints-To: abuse@newsgroups-download.com NNTP-Posting-Date: Sat, 21 Dec 2013 22:56:35 UTC Organization: Public Usenet Newsgroup Access Date: Sat, 21 Dec 2013 18:56:35 -0400 X-Received-Bytes: 3266 X-Received-Body-CRC: 3530342779 Xref: csiph.com comp.lang.java.programmer:27031 On 12/21/2013 04:04 PM, Arne Vajhøj wrote: > On 12/21/2013 1:59 PM, Arved Sandstrom wrote: >> On 12/20/2013 08:08 PM, Arne Vajhøj wrote: >>> On 12/20/2013 9:07 AM, Andreas Leitgeb wrote: >>>> I have to write code to execute runtime-specified SQL-statements, >>>> and there are two things that I wasn't able to understand from reading >>>> the javadocs: >>>> >>>> 1.) >>>> When would one call .getMoreResults() on a statement instead of just >>>> another rs.next() on the first one (obtained from >>>> stmnt.getResultSet())? >>>> Are these equivalent, or is there really a concept of multiple >>>> ResultSets, >>>> each of which has its own independent set of rows? >>> >>> Yes. >>> >>> Some databases support stored procedures returning multiple >>> result sets. >> [ SNIP ] >> >> This might just be me, but I dislike the entire idea. I am aware of the >> possibility, I've never used it. To me a stored proc (SP) should adhere >> to the same principles as functions or procedures - you try to simplify >> your components (and your application) by not having them do multiple >> things (side-effects, overly complex return values etc). > > I can follow you. > > But I have seen SP's return 20+ result sets. > > I guess that the argument is to save round trips. > > Arne > No doubt. I've never been compelled to use multiple result sets myself. I haven't not once encountered a project where anyone felt the need to use multiple result sets. So I actually Googled to find out what the rationale is. There appear to be two different things that are referred to as multiple result sets. One is multiple active result sets (MARS), which is just the ability to execute multiple batches on a single connection. I can defend this idea: expensive resource acquisition, re-use it if you can. The other is stored procs returning multiple result sets. I had no success finding any article that provided motivation for the concept: the authors of a few articles did mention that they wished not to explain *why*, but just *how*...which is faint praise in my books. :-) This particular concept seems to me to be much more "we can do this, so we will". AHS -- When a true genius appears, you can know him by this sign: that all the dunces are in a confederacy against him. -- Jonathan Swift