From: | "Dave Cramer" <Dave(at)micro-automation(dot)net> |
---|---|
To: | "'Fredrik Wendt'" <fredrik(dot)wendt(at)linux(dot)se>, <pgsql-jdbc(at)postgresql(dot)org> |
Subject: | Scrolling through cursors |
Date: | 2002-03-18 03:48:26 |
Message-ID: | 002901c1ce2f$c4d913b0$807ba8c0@inspiron |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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 ) {}
}
}
From | Date | Subject | |
---|---|---|---|
Next Message | Viacheslav N Tararin | 2002-03-18 07:15:08 | Re: JDBC Logging & log4j |
Previous Message | Dave Cramer | 2002-03-18 03:16:46 | Re: Visualization of structure (OT?) |