getObject and Aggregate SQL functions - Mailing list pgsql-jdbc

From David Esposito
Subject getObject and Aggregate SQL functions
Date
Msg-id PEEDKNLDICKECFBNGNLLAEENCBAA.esposito@newnetco.com
Whole thread Raw
List pgsql-jdbc
I think i might have found a bug in the JDBC driver ... It manifests itself
when using the getObject() call on the ResultSet for a column that is the
result of an aggregate function. It causes the application to hang on a call
to getObject().

I'm running:

PostGresSQL 7.1
jdbc7.0-1.2.jar
Sun JDK 1.3

The entire sample application source is included below, but here's the
important section:

ResultSet rs = st.executeQuery("SELECT member_id as whatever from member");

System.out.println("Results from non-aggregate query:");

while(rs.next())
{
    System.out.println("Whatever STRING = " + rs.getString(1));
    System.out.println("Whatever OBJECT = " + rs.getObject(1));
}

System.out.println("Results from aggregate query:");

ResultSet rs2 = st.executeQuery("SELECT sum(member_id) as whatever from
member");

while(rs2.next())
{
    System.out.println("Whatever STRING = " + rs2.getString(1));
    //Application hangs on this line
    System.out.println("Whatever OBJECT = " + rs2.getObject(1));
}

The following output is generated:

--------------------going to get driver--------------------
--------------------going to get connection--------------------
got connection
Results from non-aggregate query:
Whatever STRING = 63
Whatever OBJECT = 63
Whatever STRING = 201
Whatever OBJECT = 201
Whatever STRING = 207
Whatever OBJECT = 207
<SNIP>
Results from aggregate query:
Whatever STRING = 3977
<HUNG!>

So it seems like the getObject call only hangs when used on a column that is
the result of an aggregate function ... I've tried using a regular Statement
as well as a PreparedStatement ... both still hang ... I have to kill the
application (Control + C) in order to rescue the situation ..

Any advice would be greatly appreciated!

Here's the application if you'd like to compile it and try it for yourself:

import java.sql.*;

public class PostgresTester
{
  public static void main(String argv[])
  {
    try{

      System.out.println("--------------------going to get
driver--------------------");
      Class.forName("org.postgresql.Driver");
      System.out.println("--------------------going to get
connection--------------------");
      Connection c =
DriverManager.getConnection("jdbc:postgresql://10.1.159.1:5432/mydb","dbuser
1","dbpass1");
      System.out.println("got connection");

      Statement st = c.createStatement();

      ResultSet rs = st.executeQuery("SELECT member_id as whatever from
member");

      System.out.println("Results from non-aggregate query:");

      while(rs.next())
      {
        System.out.println("Whatever STRING = " + rs.getString(1));
        System.out.println("Whatever OBJECT = " + rs.getObject(1));
      }

      System.out.println("Results from aggregate query:");

      ResultSet rs2 = st.executeQuery("SELECT sum(member_id) as whatever
from member");

      while(rs2.next())
      {
        System.out.println("Whatever STRING = " + rs2.getString(1));
        System.out.println("Whatever OBJECT = " + rs2.getObject(1));
      }
    }
    catch(Exception e)
    {
      System.out.println("EXCEPTION! " + e);
    }

  }
}


pgsql-jdbc by date:

Previous
From: Barry Lind
Date:
Subject: Re: Soliciting CallableStatement ideas
Next
From: Leandro Rodrigo Saad Cruz
Date:
Subject: Error build driver