• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

moving record pointer backwards - error

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi folks
i have got a java program below for reading records from the last.it compiles fine.but when i run it says invalid cursor type.
i have used ms-access 2000 and created a dsn entry.i am using jdk1.3. will jdbc-odbc connectivity work fine only for forward record fetch.pl clarify.
regards
ram ganesh

import java.sql.*;
class test{
public static void main(String args[]) throws Exception{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc dbc:test");
Statement stmt=con.createStatement(ResultSet.FETCH_REVERSE,ResultSet.CONCUR_READ_ONLY);
ResultSet ab=stmt.executeQuery("Select * from ram");
while(ab.next()){
System.out.println(ab.getRow());
System.out.println(ab.getString(2));
if (ab.getRow()==1)
ab.previous();
}
}
}
Exception in thread "main" java.sql.SQLException: Invalid Cursor Type.
at sun.jdbc.odbc.JdbcOdbcStatement.initialize(JdbcOdbcStatement.java:140
)
at sun.jdbc.odbc.JdbcOdbcConnection.createStatement(JdbcOdbcConnection.j
ava:420)
at test.main(test.java:6)
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
while creating statement use this
"stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);"
Then, u can be able to use resultset.first() and resultset.last() and other functions suitable for ur application.
Hope this will work for u.
Hava a good day.
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ResultSet.FETCH_REVERSE is only a performance suggestion to the database that you will be processing the resultset in a reverse direction. And to compound the problem, the driver can just ignore your suggestion! If you want to use this suggestion you have to create a scrollable resultset(like above) then move to the end of the resultset and iterate through it backwards...

if you want the resultset "physically" returned to you in a reverse order you must include an order by clause in your select statement to arrange this.
Jamie
 
reply
    Bookmark Topic Watch Topic
  • New Topic