Trapping empty result set

Trapping empty result set

Post by DRif » Thu, 09 Sep 1999 04:00:00



I am using JDBC with Oracle Lite 4.0 (also known as 8i) JDBC drivers. When I
execute a select query in a database which is not fully populated, and get an
empty result set, this driver does not return an SQL exception. If I try to
populate any variables from the result set columns I get a Null Pointer
Exception.

Is there an elegant way to trap errors from queries that don't return any data?
I called Oracle Tech Support, and their suggestion was to precede each of my
queries with another query such as "select count(*) from foo". Surely I don't
have to execute two queries every time I suspect there is no data?

 
 
 

Trapping empty result set

Post by Joseph Weinstei » Thu, 09 Sep 1999 04:00:00


If no rows are returned from your query, ResultSet.next() should return
false the first time you call it. To return no rows may  be an error to you,
but it is not an error to the DBMS, or to other applications. *If* ResultSet
.next() returns true, it's a driver bug.
Joe Weinstein at BEA, the home of WebLogic


> I am using JDBC with Oracle Lite 4.0 (also known as 8i) JDBC drivers. When I
> execute a select query in a database which is not fully populated, and get an
> empty result set, this driver does not return an SQL exception. If I try to
> populate any variables from the result set columns I get a Null Pointer
> Exception.

> Is there an elegant way to trap errors from queries that don't return any data?
> I called Oracle Tech Support, and their suggestion was to precede each of my
> queries with another query such as "select count(*) from foo". Surely I don't
> have to execute two queries every time I suspect there is no data?

--
PS: Hey folks, we're hiring Java engineers for our WebLogic
    Engineering group in downtown S.F. Send me your resume.
--------------------------------------------------------------------------------
                    The Weblogic Application Server from BEA
         JavaWorld Editor's Choice Award: Best Web Application Server
  Java Developer's Journal Editor's Choice Award: Best Web Application Server
     Crossroads A-List Award: Rapid Application Development Tools for Java
Intelligent Enterprise RealWare: Best Application Using a Component Architecture
               http://weblogic.beasys.com/press/awards/index.htm

 
 
 

1. Trapping empty result set

Did you do a resultSet.next()? It should return false ... meaning no more results.
'Populating' variables without a successful next() is incorrect, though you should get a
SQLException instead of NullPointer.

It is quite proper that the driver should return a result set (albeit empty) even when
no rows were found. It should not throw a SQLException.

--
Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)

2. OLE and Word 97- Word application not showing in the font but becoming an icon

3. Empty Result Set from Stored Procedure?

4. DAO 3.6, Data controls, Passwords, RT 3112

5. unixODBC - Inline TDS Driver 1.6 - Data in result set is empty

6. adding an image

7. Variable assignment when empty result set encountered.

8. strange oracle problem - please help!!

9. HELP Needed - Heavy Load causing Sparatic Empty Result Sets (SQL 7)

10. empty result set even though there is data

11. Bug? where is the second empty result set

12. empty result set even though tere is data

13. Stored Proc returns an empty result set