From: | Thomas Kellerer <spam_eater(at)gmx(dot)net> |
---|---|
To: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Cursors for PGJDBC queries |
Date: | 2019-08-01 07:43:52 |
Message-ID: | efd07964-22fa-e285-eee0-bfa201ce29c2@gmx.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Rashmi V Bharadwaj schrieb am 01.08.2019 um 09:10:
> I am trying to set the fetch size for my ResultSet to avoid Out of
> Memory exception. I have created the Statement with
> ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY and
> ResultSet.HOLD_CURSORS_OVER_COMMIT and I've also disabled auto commit
> as mentioned in the link Getting results based on a cursor
> <https://jdbc.postgresql.org/documentation/head/query.html#query-with-cursor>.
> I am still getting Out of memory error. My SQL query is a simple
> SELECT statement to retrieve all the rows from a table. According to
> https://postgrespro.com/list/thread-id/2370772, the holdability must
> be CLOSE_CURSORS_AT_COMMIT. Could you please confirm this is a
> requirement?
To rule out the obvious: you did call Statement.setFetchSize() before calling executeQuery()?
Using
connection.setAutoCommit(false);
Statement stmt = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
stmt.setFetchSize(100);
ResultSet rs = stmt.executeQuery("....");
while (rs.next()) {
...
}
works perfectly for me, even with really large results.
From | Date | Subject | |
---|---|---|---|
Next Message | Adrian Klaver | 2019-08-01 14:28:58 | Re: adding more space to the existing server |
Previous Message | Luca Ferrari | 2019-08-01 07:32:00 | Re: Cursors for PGJDBC queries |