my dog learned polymorphism
The moose likes JDBC and Relational Databases and the fly likes moving record pointer backwards - error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "moving record pointer backwards - error" Watch "moving record pointer backwards - error" New topic

moving record pointer backwards - error

Ram Ganesh

Joined: Feb 01, 2001
Posts: 11
hi folks
i have got a java program below for reading records from the 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 clarify.
ram ganesh

import java.sql.*;
class test{
public static void main(String args[]) throws Exception{
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");
if (ab.getRow()==1)
Exception in thread "main" java.sql.SQLException: Invalid Cursor Type.
at sun.jdbc.odbc.JdbcOdbcStatement.initialize(
at sun.jdbc.odbc.JdbcOdbcConnection.createStatement(JdbcOdbcConnection.j
at test.main(
kumar lakkapragada

Joined: Apr 27, 2001
Posts: 4
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.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

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.
It is sorta covered in the JavaRanch Style Guide.
subject: moving record pointer backwards - error
It's not a secret anymore!