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

resultset contains too many rows!

From: "Nick Fankhauser" <nickf(at)ontko(dot)com>
To: "Psql-Jdbc" <pgsql-jdbc(at)postgresql(dot)org>
Subject: resultset contains too many rows!
Date: 2001-12-21 20:49:29
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-jdbc
I have a bizarre problem-

I'm using a prepared statement to select from a view. If I do the select in
psql, I get one row. If I do the same select using a prepared statement in
JDBC, I get 4 rows. The 4:1 ratio is consistent- If I loosen the select
criterion & get 25 rows in psql, I'll get 100 out of JDBC.

This application displays data via the web & uses Tomcat, so to take the
guesswork out of where the problem was coming from, I stuck a debug
statement in my method that takes data out of the resultset & puts it in a
data bean. The code looks like this:

  private CaseBean makeCaseBean(ResultSet results)
    throws DBException
      System.out.println("In makeCseBean, Processing row
      CaseBean caseB = new CaseBean();








      return caseB;
    catch (SQLException e)
      throw new DBException(e.getMessage());

here is what I get on stdout when I run this using a criterion that returns
one row in psql:

In makeCseBean, Processing row 1
In makeCseBean, Processing row 2
In makeCseBean, Processing row 3
In makeCseBean, Processing row 4

Here is the code that loops through the resultSet:

  public CaseBean[] getCases(String caseId)
    throws DBException, NoRowsException {
    try {
      ResultSet results;
      Collection cases = new ArrayList();
      synchronized (getCasesStmt) {
	    getCasesStmt.setString(1, caseId+"%");
	    results = getCasesStmt.executeQuery();
      int rows = 0;
      while ( {
      if (rows>0) {
	    return (CaseBean[])cases.toArray(new CaseBean[0]);
      else {
        throw new NoRowsException("Resulted from Case Query using ID like
    catch (SQLException e) {
      throw new DBException("SQL problem in getCases: "+e.getMessage());

Since I'm using getRow()to come up with these numbers, I know that I'm
really getting 4 rows in the resultset, not just erroneously processing the
same row 4 times. Further support for the problem being in the returned
resultset is that when I return a large number of rows with the "order by"
removed, the duplicates do not always appear next to one another in the

Here is the string that the prepared statement is created from:

    final String getCases="SELECT * FROM CASE_TYPE_DISP "+
                          "WHERE UPPER(CASE_ID) LIKE UPPER(?) "+
                          "ORDER BY CASE_ID "+
                          "LIMIT 1000";

One more clue: The *same code* works correctly (no duplications) on a
smaller test database with about 3000 rows in the view. It fails on a large
database with about 19,000 rows in the view. That's what makes this so
bizzare- I can make the error go away simply by connecting to a smaller

My environment is:

Debian Linux 2.4.14
PostgreSQL 7.1.3
jdbc7.1-2.1.jar (precompiled version)
IBM Java2

Any Ideas??

Thanks Everyone!


Nick Fankhauser  nickf(at)ontko(dot)com  Phone 1.765.935.4283  Fax 1.765.962.9788
Ray Ontko & Co.     Software Consulting Services

pgsql-jdbc by date

Next:From: Ned WolpertDate: 2001-12-22 18:37:36
Subject: Submittal for JDBC Pooling driver (For 7.3)
Previous:From: Daniel GermainDate: 2001-12-21 18:59:10
Subject: QueryExecutor NullPointerException invalid Connection?

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