Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.databases > #389

Re: java.sql.SQLException

Path csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!86597e80!not-for-mail
From joeNOSPAM@BEA.com.remove-dii-this
Subject Re: java.sql.SQLException
Message-ID <c8a80d5e-5cd4-412a-bc3f-86fe67f1768f@p2g2000prn.googlegroups.com> (permalink)
X-Comment-To comp.lang.java.databases
Newsgroups comp.lang.java.databases
In-Reply-To <nospam-75B553.12314806122008@nntp.motzarella
References <nospam-75B553.12314806122008@nntp.motzarella
Content-Type text/plain; charset=IBM437
Content-Transfer-Encoding 8bit
X-Gateway time.synchro.net [Synchronet 3.15a-Win32 NewsLink 1.92]
Lines 47
Date Wed, 27 Apr 2011 15:23:26 GMT
NNTP-Posting-Host 96.60.20.240
X-Complaints-To news@tds.net
X-Trace newsreading01.news.tds.net 1303917806 96.60.20.240 (Wed, 27 Apr 2011 10:23:26 CDT)
NNTP-Posting-Date Wed, 27 Apr 2011 10:23:26 CDT
Organization TDS.net
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.databases:389

Show key headers only | View raw


  To: comp.lang.java.databases
Whatever driver returns a result set from an executeQuery() call whose
SQL does not include an actual query (request for data rows), is a
broken driver. I know this includes some big name drivers. Instead
it should throw an exception, not deliver some dummy resultset.

If you don't know what the SQL is doing, use execute(), and observe
what
it returns to know what to do first, then step through any possible
remaining returns using getMoreResults() and what it returns.

Here is the ideal code for running SQL you don't know about through
JDBC.

boolean getResultSetNow = stmt.execute();
   int updateCount = -1;

   while (true) { // handle all the in-line results from any stored
procedure or SQL
     if (getResultSetNow) {
       ResultSet r = stmt.getResultSet();
       while (r.next()) {
         // fully process result set before calling getMoreResults()
again!
       }
       r.close();
     } else {
       updateCount = stmt.getUpdateCount();
       if (updateCount  != -1) { // it's a valid update count
         System.out.println("Reporting an update count of " +
updateCount);
       }
     }
     if ((!getResultSetNow) && (updateCount == -1)) break; // done
with loop, finished all the returns
     getResultSetNow = stmt.getMoreResults();
   }
   // if this is a CallableStatement, get output parameters now, after
the loop


Joe Weinstein at Oracle

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.databases | Previous | Next | Find similar


Thread

Re: java.sql.SQLException joeNOSPAM@BEA.com.remove-dii-this - 2011-04-27 15:23 +0000

csiph-web