Re: Scrolling through cursors

From: Peter V Cooper <pvcooper(at)adelphia(dot)net>
To: <Dave(at)micro-automation(dot)net>, "'Fredrik Wendt'" <fredrik(dot)wendt(at)linux(dot)se>, <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Scrolling through cursors
Date: 2002-03-18 15:51:38
Message-ID: 5.1.0.14.0.20020318071512.03a41678@mail.dc3.adelphia.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

For my information; this means I probably need a
new connection object for each cursor due to the fact
that it is within a transaction and those are serial in
nature by default on a connection even though this
is a pure select statement. This begs the question
of how expensive is a new connection. Is it a new
thread or process on the backend? I think the answer
is process. Again FMI, why is a cursor necessarily
within a transaction? Also I think any connection
object is serialized at the backend anyway true/false?

TIA for any responses.

BTW, this is not a complaint by me as most modern UNIX'es
are reasonably efficient at process creation and destruction
especially when the initial data and stack segments are
reasonable in size since the Text segment is irrelevant.
Might be more of a problem for other OS'es.

At 10:48 PM 3/17/2002 -0500, Dave Cramer wrote:
>Fredik
>
>Here is some code which uses cursors
>
>Dave
>
> public void testCursor()
> {
> Connection con = null;
> try {
> con = getConnection();
>
> // cursors work inside a transaction
> con.setAutoCommit(false);
>
> Statement stmt = con.createStatement();
>
> // sufficiently long select as to get us something we can scroll
>through
> stmt.execute("declare cursorname cursor for select * from
>pg_class");
>
> ResultSet rs = stmt.executeQuery("fetch 10 from cursorname");
>
> while (rs.next()){
> System.out.println(rs.getString(1));
> }
> rs.close();
>
> // close the cursor
> con.commit();
>
> }
> catch (Exception ex)
> {
> ex.printStackTrace();
> }
> finally
> {
> try {
> if ( con != null )
> con.close();
> }catch ( SQLException ex ) {}
> }
>
> }
>
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Gunnar Rønning 2002-03-18 15:53:49 Re: JDBC Logging & log4j
Previous Message Marin Dimitrov 2002-03-18 15:38:37 Re: globally unique ID