Thread: NullPointerExceptions in empty ResultSets

NullPointerExceptions in empty ResultSets

From
"Floyd Shackelford"
Date:
 
i just upgraded to the latest jdbc driver and am now getting errors in empty ResultSets (i.e. the sql select returned 0 rows) where i used to not get an error. here are some examples:
 
java.lang.NullPointerException at org.postgresql.jdbc2.ResultSet.beforeFirst(ResultSet.java:876)
java.lang.NullPointerException at org.postgresql.jdbc2.ResultSet.last(ResultSet.java:1133)
 
please let me know if this is an error and if so:
 
1. how do i work around it for now
2. when can i have a new version of the jdbc jar file?

Regards,

Floyd Shackelford
4 Peaks Technology Group, Inc.
VOICE: 334.735.9428
FAX:   916.404.7125
EMAIL:
FloydS@4PeaksTech.com
ICQ #: 161371538

acta non verba

 

Re: NullPointerExceptions in empty ResultSets

From
Dave Cramer
Date:
Try downloading the dev jar

I just tried

  public void testEmptyResult()
  {
    try
    {
      Statement stmt = con.createStatement();
      ResultSet rs = stmt.executeQuery("SELECT * FROM testrs where
id=100");
      rs.beforeFirst();
      rs.afterLast();
      assertTrue(!rs.first());
      assertTrue(!rs.last());
      assertTrue(!rs.next());


    }
    catch ( Exception ex )
    {
      fail( ex.getMessage() );
    }

and it passed with no problem

DAve
On Thu, 2002-06-13 at 14:00, Floyd Shackelford wrote:
>
> i just upgraded to the latest jdbc driver and am now getting errors in empty
> ResultSets (i.e. the sql select returned 0 rows) where i used to not get an
> error. here are some examples:
>
> java.lang.NullPointerException at
> org.postgresql.jdbc2.ResultSet.beforeFirst(ResultSet.java:876)
>
> java.lang.NullPointerException at
> org.postgresql.jdbc2.ResultSet.last(ResultSet.java:1133)
>
> please let me know if this is an error and if so:
>
> 1. how do i work around it for now
> 2. when can i have a new version of the jdbc jar file?
>
> Regards,
>
> Floyd Shackelford
> 4 Peaks Technology Group, Inc.
> VOICE: 334.735.9428
> FAX:   916.404.7125
> EMAIL: FloydS@4PeaksTech.com
> ICQ #: 161371538
> acta non verba
>
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.370 / Virus Database: 205 - Release Date: 6/5/2002
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.370 / Virus Database: 205 - Release Date: 6/5/2002
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.370 / Virus Database: 205 - Release Date: 6/5/2002




Re: NullPointerExceptions in empty ResultSets

From
tony
Date:
On Thu, 2002-06-13 at 20:16, Dave Cramer wrote:

> > i just upgraded to the latest jdbc driver and am now getting errors in empty
> > ResultSets (i.e. the sql select returned 0 rows) where i used to not get an
> > error. here are some examples:

Am I missing something or shouldn't your java code handle empty result
sets?

All my JSPs have a "show if not empty" logic (built lovingly by
Dreamweaver XP) on resultsets.

Cheers

Tony Grant

--
RedHat Linux on Sony Vaio C1XD/S
http://www.animaproductions.com/linux2.html
Macromedia UltraDev with PostgreSQL
http://www.animaproductions.com/ultra.html


Re: NullPointerExceptions in empty ResultSets

From
"Floyd Shackelford"
Date:
i figured out what the problem was.

in my code, i was doing this:

  resultSet.close()
  [snip a whole bunch of code]
  resultSet.last()
  resultSet.getRow();

in the previous version of the jdbc drivers, it quietly handled last() on a
closed result set and returned 0 from getRow() on a closed result set. now,
i get a null pointer exception when i call anything on a closed result set.

i suggest this is no bug and that it actually helped me improve my code.

sorry for the false alarm.

Regards,

Floyd Shackelford
4 Peaks Technology Group, Inc. <http://www.4peakstech.com/>
VOICE: 334.735.9428
FAX:   916.404.7125
EMAIL: FloydS@4PeaksTech.com <mailto:FloydS@4PeaksTech.com>
ICQ #: 161371538

acta non verba



-----Original Message-----
From: pgsql-jdbc-owner@postgresql.org
[mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Dave Cramer
Sent: Thursday, June 13, 2002 1:17 PM
To: floyds@4peakstech.com
Cc: pgsql-jdbc@postgresql.org
Subject: Re: [JDBC] NullPointerExceptions in empty ResultSets


Try downloading the dev jar

I just tried

  public void testEmptyResult()
  {
    try
    {
      Statement stmt = con.createStatement();
      ResultSet rs = stmt.executeQuery("SELECT * FROM testrs where
id=100");
      rs.beforeFirst();
      rs.afterLast();
      assertTrue(!rs.first());
      assertTrue(!rs.last());
      assertTrue(!rs.next());


    }
    catch ( Exception ex )
    {
      fail( ex.getMessage() );
    }

and it passed with no problem

DAve
On Thu, 2002-06-13 at 14:00, Floyd Shackelford wrote:
>
> i just upgraded to the latest jdbc driver and am now getting errors in
empty
> ResultSets (i.e. the sql select returned 0 rows) where i used to not get
an
> error. here are some examples:
>
> java.lang.NullPointerException at
> org.postgresql.jdbc2.ResultSet.beforeFirst(ResultSet.java:876)
>
> java.lang.NullPointerException at
> org.postgresql.jdbc2.ResultSet.last(ResultSet.java:1133)
>
> please let me know if this is an error and if so:
>
> 1. how do i work around it for now
> 2. when can i have a new version of the jdbc jar file?
>
> Regards,
>
> Floyd Shackelford
> 4 Peaks Technology Group, Inc.
> VOICE: 334.735.9428
> FAX:   916.404.7125
> EMAIL: FloydS@4PeaksTech.com
> ICQ #: 161371538
> acta non verba
>
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.370 / Virus Database: 205 - Release Date: 6/5/2002
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.370 / Virus Database: 205 - Release Date: 6/5/2002
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.370 / Virus Database: 205 - Release Date: 6/5/2002




---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.370 / Virus Database: 205 - Release Date: 6/5/2002

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.370 / Virus Database: 205 - Release Date: 6/5/2002


Re: NullPointerExceptions in empty ResultSets

From
Barry Lind
Date:
Floyd,

Can you provide an simple test case that reproduces the problem?

thanks,
--Barry

Floyd Shackelford wrote:
>
> i just upgraded to the latest jdbc driver and am now getting errors
> in empty ResultSets (i.e. the sql select returned 0 rows) where i used
> to not get an error. here are some examples:
>
> java.lang.NullPointerException at
> org.postgresql.jdbc2.ResultSet.beforeFirst(ResultSet.java:876)
> java.lang.NullPointerException at
> org.postgresql.jdbc2.ResultSet.last(ResultSet.java:1133)
>
> please let me know if this is an error and if so:
>
> 1. how do i work around it for now
> 2. when can i have a new version of the jdbc jar file?
>
> Regards,
>
> Floyd Shackelford
> 4 Peaks Technology Group, Inc. <http://www.4peakstech.com/>
> VOICE: 334.735.9428
> FAX:   916.404.7125
> EMAIL: FloydS@4PeaksTech.com <mailto:FloydS@4PeaksTech.com>
> ICQ #: 161371538
>
> /acta non verba/
>
>



Re: NullPointerExceptions in empty ResultSets

From
"Thomas Vatter"
Date:
I have the same type of "show if not empty" logic in a larger application. I
should do a port from oracle to postgres but I had to stop because different
application logic would be necessary.

> -----Ursprüngliche Nachricht-----
> Von: pgsql-jdbc-owner@postgresql.org
> [mailto:pgsql-jdbc-owner@postgresql.org]Im Auftrag von tony
> Gesendet: Donnerstag, 13. Juni 2002 20:48
> An: Dave Cramer
> Cc: floyds@4peakstech.com; pgsql-jdbc@postgresql.org
> Betreff: Re: [JDBC] NullPointerExceptions in empty ResultSets
>
>
> On Thu, 2002-06-13 at 20:16, Dave Cramer wrote:
>
> > > i just upgraded to the latest jdbc driver and am now
> getting errors in empty
> > > ResultSets (i.e. the sql select returned 0 rows) where i
> used to not get an
> > > error. here are some examples:
>
> Am I missing something or shouldn't your java code handle empty result
> sets?
>
> All my JSPs have a "show if not empty" logic (built lovingly by
> Dreamweaver XP) on resultsets.
>
> Cheers
>
> Tony Grant
>
> --
> RedHat Linux on Sony Vaio C1XD/S
> http://www.animaproductions.com/linux2.html
> Macromedia UltraDev with PostgreSQL
> http://www.animaproductions.com/ultra.html
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>