wood burning stoves 2.0*
The moose likes JDBC and the fly likes JDBC2.0 feature.  rs.absolute and relative( ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC2.0 feature.  rs.absolute and relative( )" Watch "JDBC2.0 feature.  rs.absolute and relative( )" New topic
Author

JDBC2.0 feature. rs.absolute and relative( )

popeye tb
Greenhorn

Joined: Sep 02, 2003
Posts: 3
Hi,
Can Pls anyone help me out wats wrong with the following code.
--------------------------------------
ResultSet srs = stmt.executeQuery("SELECT * FROM COFFEES");
srs.absolute(4);
int rowNum = srs.getRow(); // rowNum should be 4
System.out.println("rowNum should be 4 :" + rowNum);
srs.relative(-2);
rowNum = srs.getRow(); // rowNum should be 2
System.out.println("rowNum should be 2 :" + rowNum);
srs.relative(2);
rowNum = srs.getRow(); // rowNum should be 4
System.out.println("rowNum should be 4 :" + rowNum);
--------------------------------------------
The output i get is correct in this case..as,
rowNum should be 4 : 4
rowNum should be 2 : 2
rowNum should be 4 : 4
But once i change the line below :
srs.relative(-2);
to
srs.relative(-3);
I get the following error :
SQL Exception
SQL State : null
Message : Cursor is positioned before the resultset.
Shouldnt the out be as below :
rowNum should be 4 : 4
rowNum should be 2 : 1
rowNum should be 4 : 4
The second line pointing to row one..
Thanks.
Dana Hanna
Ranch Hand

Joined: Feb 28, 2003
Posts: 227
No clue why that's not working... Scrollable resultsets are always a pain.
Oh, and the final output should be:
popeye tb
Greenhorn

Joined: Sep 02, 2003
Posts: 3
Ya true, the output shd be 4 1 3. But it always show the error instead. Thanks anyway.
popeye tb
Greenhorn

Joined: Sep 02, 2003
Posts: 3
Hi i noticed something.. when i compile the code as below :
--------------------------------------
ResultSet srs = stmt.executeQuery("SELECT * FROM COFFEES");
srs.absolute(4);
int rowNum = srs.getRow(); // rowNum should be 4
System.out.println("rowNum should be 4 :" + rowNum);
srs.relative(-2);
srs.previous()
rowNum = srs.getRow(); // rowNum should be 2
System.out.println("rowNum should be 2 :" + rowNum);
srs.relative(2);
rowNum = srs.getRow(); // rowNum should be 4
System.out.println("rowNum should be 4 :" + rowNum);
--------------------------------------------
the second line is able to point to the first row. The output is :
rowNum should be 4 : 4
rowNum should be 2 : 1
rowNum should be 4 : 3
but if i use,
srs.relative(-1);
instead of,
srs.previous();
i get the same error :
rowNum should be 4 : 4
rowNum should be 2 : 0
SQL Exception
SQL State : null
Message : Cursor is positioned before the resultset.
Pls HELP!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC2.0 feature. rs.absolute and relative( )
 
Similar Threads
Difference between rowid and rownum in sql query??
sqlserver select where rownum between
Prepared Statement not closing cursor
help whit ResultSet
Calling Oracle Function that returns %ROWTYPE