Thread: executeQuery

executeQuery

From
"Lufkin, Brad"
Date:
I'm executing an SQL query using the following code:

    Connection connection =
DriverManager.getConnection(url,user,password);
    Statement statement = connection.createStatement();
    ResultSet resultSet = statement.executeQuery("SELECT * FROM
someTable");

This works except that the third statement doesn't return until the query is
complete. This contrasts with the behavior of other databases (such as
Informix) where the query returns immediately, thus allowing the result set
metadata to be analyzed before the result set is.
Is there any way to force the executeQuery to return immediately?
If not, is there some way to limit the results of the query to the first n
rows, where n is some reasonable number?

Re: executeQuery

From
Fernando Nasser
Date:
Lufkin, Brad wrote:
> I'm executing an SQL query using the following code:
>
>     Connection connection =
> DriverManager.getConnection(url,user,password);
>     Statement statement = connection.createStatement();
>     ResultSet resultSet = statement.executeQuery("SELECT * FROM
> someTable");
>
> This works except that the third statement doesn't return until the query is
> complete. This contrasts with the behavior of other databases (such as
> Informix) where the query returns immediately, thus allowing the result set
> metadata to be analyzed before the result set is.
> Is there any way to force the executeQuery to return immediately?
> If not, is there some way to limit the results of the query to the first n
> rows, where n is some reasonable number?
>

You can either use LIMIT <n> in the SELECT statement itself or use the
setFetchSize() inside a transaction or with server-side prepared statements.



--
Fernando Nasser
Red Hat Canada Ltd.                     E-Mail:  fnasser@redhat.com
2323 Yonge Street, Suite #300
Toronto, Ontario   M4P 2C9


Re: executeQuery

From
"Lufkin, Brad"
Date:
Fernando:
is the LIMIT qualifier part of the SQL standard or a Postgres extension?
Also, I tried the statement.setFetchSize() and got a "method not
implemented" error. Can you send me a code fragment that illustrates what
you mean?
Thanks, Brad

-----Original Message-----
From: Fernando Nasser [mailto:fnasser@redhat.com]
Sent: Thursday, August 07, 2003 12:47 PM
To: Lufkin, Brad
Cc: 'postgres'
Subject: Re: [JDBC] executeQuery


Lufkin, Brad wrote:
> I'm executing an SQL query using the following code:
>
>     Connection connection =
> DriverManager.getConnection(url,user,password);
>     Statement statement = connection.createStatement();
>     ResultSet resultSet = statement.executeQuery("SELECT * FROM
> someTable");
>
> This works except that the third statement doesn't return until the query
is
> complete. This contrasts with the behavior of other databases (such as
> Informix) where the query returns immediately, thus allowing the result
set
> metadata to be analyzed before the result set is.
> Is there any way to force the executeQuery to return immediately?
> If not, is there some way to limit the results of the query to the first n
> rows, where n is some reasonable number?
>

You can either use LIMIT <n> in the SELECT statement itself or use the
setFetchSize() inside a transaction or with server-side prepared statements.



--
Fernando Nasser
Red Hat Canada Ltd.                     E-Mail:  fnasser@redhat.com
2323 Yonge Street, Suite #300
Toronto, Ontario   M4P 2C9


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Re: executeQuery

From
Fernando Nasser
Date:
Lufkin, Brad wrote:
> Fernando:
> is the LIMIT qualifier part of the SQL standard or a Postgres extension?

PostgreSQL.

> Also, I tried the statement.setFetchSize() and got a "method not
> implemented" error. Can you send me a code fragment that illustrates what
> you mean?

Humm, it is in the current driver, but I don't know exactly when.

As for an aexample, just browse the list archives for the last few days.
Look for setFetchSize in the subject.

Regards,
Fernando

--
Fernando Nasser
Red Hat Canada Ltd.                     E-Mail:  fnasser@redhat.com
2323 Yonge Street, Suite #300
Toronto, Ontario   M4P 2C9


Re: executeQuery

From
Barry Lind
Date:
Brad,

By current, Fernando means the current development version of the
driver.  This functionality does not exist in the current production
(i.e. 7.3.4) version of the driver.  You can download from
jdbc.postgresql.org, or build from cvs sources.

thanks,
--Barry

Fernando Nasser wrote:
> Lufkin, Brad wrote:
>
>> Fernando:
>> is the LIMIT qualifier part of the SQL standard or a Postgres extension?
>
>
> PostgreSQL.
>
>> Also, I tried the statement.setFetchSize() and got a "method not
>> implemented" error. Can you send me a code fragment that illustrates what
>> you mean?
>
>
> Humm, it is in the current driver, but I don't know exactly when.
>
> As for an aexample, just browse the list archives for the last few days.
> Look for setFetchSize in the subject.
>
> Regards,
> Fernando
>