Re: Statement.executeQuery() and no results

Lists: pgsql-jdbc
From: Sailesh Krishnamurthy <sailesh(at)cs(dot)berkeley(dot)edu>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Statement.executeQuery() and no results
Date: 2003-07-23 02:48:49
Message-ID: bxyy8yqdkku.fsf@datafix.cs.berkeley.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc


Folks

When we run a query that produces no results, executeQuery() returns
an exception instead of a ResultSet object for which the first call to
next() returns false. (This is with a driver for pgsql 7.3.2)

Here is some code in AbstractJdbc1Statement.java

/*
* A Prepared SQL query is executed and its ResultSet is returned
*
* @return a ResultSet that contains the data produced by the
* * query - never null
* @exception SQLException if a database access error occurs
*/
public java.sql.ResultSet executeQuery() throws SQLException
{
this.execute(false);
while (result != null && !((AbstractJdbc1ResultSet)result).reallyResultSet())
result = ((AbstractJdbc1ResultSet)result).getNext();
if (result == null)
throw new PSQLException("postgresql.stat.noresult");
return result;
}

Is my understanding correct ? Is this working as designed ? I'm not
convinced that this is as per the spec. I would rather see a ResultSet
object returned instead of an exception.

--
Pip-pip
Sailesh
http://www.cs.berkeley.edu/~sailesh


From: Kris Jurka <books(at)ejurka(dot)com>
To: Sailesh Krishnamurthy <sailesh(at)cs(dot)berkeley(dot)edu>
Cc: <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Statement.executeQuery() and no results
Date: 2003-07-23 02:55:07
Message-ID: Pine.LNX.4.33.0307222253260.6056-100000@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

On 22 Jul 2003, Sailesh Krishnamurthy wrote:

>
> Folks
>
> When we run a query that produces no results, executeQuery() returns
> an exception instead of a ResultSet object for which the first call to
> next() returns false. (This is with a driver for pgsql 7.3.2)
>

This code will throw an exception if you try calling executeQuery with a
non-select statement. For example an UPDATE. If you are getting
unexpected exceptions please post a test case here.

Kris Jurka


From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Sailesh Krishnamurthy <sailesh(at)cs(dot)berkeley(dot)edu>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Statement.executeQuery() and no results
Date: 2003-07-23 03:01:33
Message-ID: 20030723030133.GN31669@opencloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

On Tue, Jul 22, 2003 at 07:48:49PM -0700, Sailesh Krishnamurthy wrote:
>
> Folks
>
> When we run a query that produces no results, executeQuery() returns
> an exception instead of a ResultSet object for which the first call to
> next() returns false. (This is with a driver for pgsql 7.3.2)

JDBC distinguishes between statements that return a (possibly empty)
ResultSet (e.g. any SELECT) that should use executeQuery() and statements
that return no ResultSet (e.g. INSERT or CREATE TABLE) that should use
executeUpdate().

The JDBC javadoc is a bit clearer than the driver's javadoc on this.

-O


From: Barry Lind <blind(at)xythos(dot)com>
To: sailesh(at)cs(dot)berkeley(dot)edu
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Statement.executeQuery() and no results
Date: 2003-07-23 03:26:51
Message-ID: 3F1E007B.9080506@xythos.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-jdbc

Sailesh,

Something else must be going on here. As under normal circumstances you
will always get ResultSet even if the query returns now rows. Can you
send test case that reproduces the problem?

thanks,
--Barry

Sailesh Krishnamurthy wrote:
> Folks
>
> When we run a query that produces no results, executeQuery() returns
> an exception instead of a ResultSet object for which the first call to
> next() returns false. (This is with a driver for pgsql 7.3.2)
>
> Here is some code in AbstractJdbc1Statement.java
>
> /*
> * A Prepared SQL query is executed and its ResultSet is returned
> *
> * @return a ResultSet that contains the data produced by the
> * * query - never null
> * @exception SQLException if a database access error occurs
> */
> public java.sql.ResultSet executeQuery() throws SQLException
> {
> this.execute(false);
> while (result != null && !((AbstractJdbc1ResultSet)result).reallyResultSet())
> result = ((AbstractJdbc1ResultSet)result).getNext();
> if (result == null)
> throw new PSQLException("postgresql.stat.noresult");
> return result;
> }
>
> Is my understanding correct ? Is this working as designed ? I'm not
> convinced that this is as per the spec. I would rather see a ResultSet
> object returned instead of an exception.
>