Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!border3.nntp.ams.giganews.com!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 20 Dec 2013 10:29:45 -0600 Date: Fri, 20 Dec 2013 16:29:43 +0000 From: lipska the kat <"lipskathekat at yahoo dot co dot uk"> Organization: Trollbusters 3 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: JDBC: getMoreResults() versus rs.next() & autoGeneratedKeys References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Message-ID: Lines: 49 X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-4uZkP1p8yxmEjXZYgaph/8PsPoC69AoMNaAV9G+bVk8qLq5DrY+QavBtYDuRDl8wg1RxIW7R5E2NGAP!MfWUbRoNbHE08/q/YAlvaj6yVGrYnmdmZvtbL/jxambthut8uOp919UokQP3hQy12KC52IpNAHvv X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3445 Xref: csiph.com comp.lang.java.programmer:27001 On 20/12/13 14:07, 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? IIRC multiple ResultSet[s] can be returned from a stored procedure, in this case you would need to iterate over the ResultSet[s] using the method getResultSet() to get the first results and getMoreResults() to check if there are more results. If there are, calling getResultSet() again would return the next results. I've never seen a single sql statement that would return multiple result sets but this doesn't mean it's not possible (obviously) > 2.) > As I don't know the statement beforehand, I can't decide at coding > time, if it might be an "insert" > eventually returning a serial key, > and thusly requiring the argument RETURN_GENERATED_KEYS), or a select > that will need cursor-like treatment such as passing resultSetType, > resultSetConcurrency and resultSetHoldability flags. > > How would I tell the JDBC engine, that if it is a select then it > should pass certain flags, and if it is an insert, then I would be > interested in the generated keys? prepareStatement() doesn't seem to > have an overload to accept both variants. You would do this in Java, surely. Use some abstract factory type mechanism to generate a suitable class depending on the type of query. I can't immediately see a way of doing this without identifying the 'type' of the statement before it's executed. > Finally, why isn't RETURN_GENERATED_KEYS the default, anyway? [guess]Because keys aren't always generated perhaps? > Seasonal Greetings, and thanks in advance > -- Lipska the KatŠ: Troll hunter, sandbox destroyer, treacherous feline and farscape dreamer of Aeryn Sun GNU/Linux user #560883 - http://www.linuxcounter.net