Skip site navigation (1) Skip section navigation (2)

Cursor problems

From: Jeffrey Melloy <jmelloy(at)visualdistortion(dot)org>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Cursor problems
Date: 2006-07-08 20:27:37
Message-ID: 083DBFCC-8EAC-4A5F-BD61-3A82DFC45E5E@visualdistortion.org (view raw or flat)
Thread:
Lists: pgsql-jdbc
I was having trouble doing checkpoint commits on a cursor.  It's  
possible I'm misunderstanding something basic, but it seems like  
commiting on the same connection a cursor is on breaks the cursor.

Here's a pared-down snippet of code giving me the problem:

conn.setAutoCommit(false);

             pstmt = conn.prepareStatement("SELECT crash_id FROM  
crash.crash_logs");
             pstmt.setFetchSize(50);

             rs = pstmt.executeQuery();

             pstmt = conn.prepareStatement("insert into blah " +
                     "values (?)");

             while(rs.next()) {
                 pstmt.setInt(1, rs.getInt("crash_id"));

                 pstmt.executeUpdate();

                 if(rs.getRow() % 50 == 0) {
                     System.out.println("Committing " + rs.getRow());
                     conn.commit();
                 }
             }

             conn.commit();

When I run it, I get the following error after the commit:
ERROR: portal "C_3" does not exist

I solved it by using two separate connections, but I'm not sure if  
this is a bug or a misunderstanding on my part.

Jeff

Responses

pgsql-jdbc by date

Next:From: Oliver JowettDate: 2006-07-08 21:55:34
Subject: Re: Cursor problems
Previous:From: Mark LewisDate: 2006-07-07 20:08:45
Subject: Re: Encoding

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group