Re: Scrolling through cursors

From: "Dave Cramer" <Dave(at)micro-automation(dot)net>
To: "'Peter V Cooper'" <pvcooper(at)adelphia(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 16:12:26
Message-ID: 005001c1ce97$b1df9cd0$807ba8c0@inspiron
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Peter,

I use a connection pool to deal with startup penalties, which I think
are significant.

It is a process on the backend.

Not sure what you mean by serialized on the backend?

Dave

> -----Original Message-----
> From: Peter V Cooper [mailto:pvcooper(at)adelphia(dot)net]
> Sent: Monday, March 18, 2002 10:52 AM
> To: Dave(at)micro-automation(dot)net; 'Fredrik Wendt';
> pgsql-jdbc(at)postgresql(dot)org
> Subject: Re: [JDBC] Scrolling through cursors
>
>
> 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

Browse pgsql-jdbc by date

  From Date Subject
Next Message Marin Dimitrov 2002-03-18 17:09:07 jdbc url
Previous Message Gunnar Rønning 2002-03-18 15:53:49 Re: JDBC Logging & log4j