Обсуждение: getMoreResults() returns false incorrectly

Поиск
Список
Период
Сортировка

getMoreResults() returns false incorrectly

От
Bob Kline
Дата:
[Second submission; first seems to have disappeared.]

I tried to search the list archives, but the search engine appears to be
broken (comes back with an http 404 error).

Using the Postgresql JDBC driver (I'm testing with jdbc7.0-1.1.jar) it
appears that Statement.getMoreResults() returns false even if there is a
result set from the query just executed.
   Statement stmt = conn.createStatement();   stmt.execute("SELECT * FROM t");   if (stmt.getMoreResults()) {
ResultSetrs = stmt.getResultSet();       while (rs.next()) {           // process row ....       }   }
 

The call to getMoreResults() returns false consistently.  If the call is
replaced with 'if (true) ...' then the code to get the result set and
process the rows works fine.

Accoring to the JDBC docs, this method should return "true if the next
result is a ResultSet; false if it is an update count or there are no
more results."  There is no update count (as confirmed by
getUpdateCount()).

Is this a known problem?  If this method doesn't work as documented,
it's impossible to "work with an unknown SQL string" as the
documentation for execute() indicates we should be able to (without
parsing the SQL query).

-- 
Bob Kline
mailto:bkline@rksystems.com
http://www.rksystems.com




Re: getMoreResults() returns false incorrectly

От
Bob Kline
Дата:
On Tue, 20 Jun 2000, Max Khon wrote:

> hi, there!
> 
> try `stmt.executeQuery(...)' instead of `stmt.execute(...)'

Thanks for the suggestion, but the two methods are intended for
different purposes.  The former is appropriate when you know in advance
there is exactly one result set produced by the query.  The latter is
intended to be used (in the words of the Javadoc documentation) when
working with "an unknown SQL string" which might return zero, one, or
multiple result sets.  I need the latter functionality, so
executeQuery() isn't appropriate in this case.

Here's the description of the execute() method and its supporting
methods from Sun's JDBC documentation
(http://java.sun.com/j2se/1.3/docs/guide/jdbc/spec/jdbc-spec.frame7.html):

7.1.4 Optional or multiple ResultSets

Normally we expect that SQL statements will be executed using either
executeQuery (which returns a single ResultSet) or executeUpdate (which
can be used for any kind of database modification statement and which
returns a count of the rows updated).

However under some circumstances an application may not know whether a
given statement will return a ResultSet until the statement has
executed. In addition, some stored procedures may return several
different ResultSets and/or update counts.

To accommodate these needs we provide a mechanism so that an application
can execute a statement and then process an arbitrary collection of
ResultSets and update counts. This mechanism is based on a fully general
"execute" method, supported by three other methods, getResultSet,
getUpdateCount, and getMoreResults. These methods allow an application
to explore the statement results one at a time and to determine if a
given result was a ResultSet or an update count.


-- 
Bob Kline
mailto:bkline@rksystems.com 
http://www.rksystems.com