Skip site navigation (1) Skip section navigation (2)

getObject and Aggregate SQL functions

From: "David Esposito" <esposito(at)newnetco(dot)com>
To: <pgsql-jdbc(at)postgresql(dot)org>, <pgsql-general(at)postgresql(dot)org>
Subject: getObject and Aggregate SQL functions
Date: 2001-04-24 20:20:37
Message-ID: PEEDKNLDICKECFBNGNLLAEENCBAA.esposito@newnetco.com (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-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

Next:From: Leandro Rodrigo Saad CruzDate: 2001-04-25 22:29:48
Subject: Error build driver
Previous:From: Barry LindDate: 2001-04-24 17:39:31
Subject: Re: Soliciting CallableStatement ideas

pgsql-general by date

Next:From: pgsql-generalDate: 2001-04-24 20:26:24
Subject: Re: Question on Bizarre Sorting (ORDER BY in 7.1) (fwd)
Previous:From: Joel BurtonDate: 2001-04-24 20:14:10
Subject: Re: Insert data into multiple tables

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group