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


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

Re: java.sql.SQLException

From joeNOSPAM@BEA.com.remove-dii-this
Subject Re: java.sql.SQLException
Message-ID <c8a80d5e-5cd4-412a-bc3f-86fe67f1768f@p2g2000prn.googlegroups.com> (permalink)
Newsgroups comp.lang.java.databases
References <nospam-75B553.12314806122008@nntp.motzarella
Date 2011-04-27 15:23 +0000
Organization TDS.net

Show all headers | 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