Scrolling through cursors - Mailing list pgsql-jdbc

From Dave Cramer
Subject Scrolling through cursors
Date
Msg-id 002901c1ce2f$c4d913b0$807ba8c0@inspiron
Whole thread Raw
In response to Visualization of structure (OT?)  (Fredrik Wendt <fredrik.wendt@linux.se>)
Responses Re: Scrolling through cursors
List pgsql-jdbc
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 ) {}
    }

  }



pgsql-jdbc by date:

Previous
From: "Dave Cramer"
Date:
Subject: Re: Visualization of structure (OT?)
Next
From: Viacheslav N Tararin
Date:
Subject: Re: JDBC Logging & log4j