my dog learned polymorphism*
The moose likes JDBC 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
Bookmark "moving record pointer backwards - error" Watch "moving record pointer backwards - error" New topic
Author

moving record pointer backwards - error

Ram Ganesh
Greenhorn

Joined: Feb 01, 2001
Posts: 11
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)
kumar lakkapragada
Greenhorn

Joined: Apr 27, 2001
Posts: 4
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.
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.
Jamie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: moving record pointer backwards - error
 
Similar Threads
Code works in main() but not in a handler
problem with isLast()!
SQLException : Invalid cursor state
Database URL
How to insert a file in oracle blob object