Hallo,
I've have a strange effect that I don't understand.
If the "fetchSize" of a result is smaller that the size of a result and
I move the cursor position to last, ResultSet.getRow() returns -1.
But the cursor is on the right row if I look at the values in the result.
example:
import java.sql.*;
public class CursorPosition3 {
static String server = "localhost";
static String db = "TST";
static String user = "DBA";
static String password = "DBA";
public static void main (String[] args){
String url = "jdbc:sapdb://" + server + "/"+ db;
//String url = "jdbc:adabasd://" + server + ":7200/"+ db;
try {
Class.forName("com.sap.dbtech.jdbc.DriverSapDB");
//Class.forName("de.sag.jdbc.adabasd.ADriver");
Connection connect = DriverManager.getConnection(url, user, password);
connect.setAutoCommit(true);
// Driver information
DatabaseMetaData meta = connect.getMetaData();
System.out.println("Driver version: " + meta.getDriverVersion());
// Creating table for test
System.out.println("Creating table 'CURSORPOSITION'");
connect.createStatement().executeUpdate(
"CREATE TABLE CURSORPOSITION(ID INTEGER NOT NULL)");
// Inserting data
System.out.println("Inserting data to table 'CURSORPOSITION' (10
rows)");
PreparedStatement pstmt = connect.prepareStatement(
"INSERT INTO CURSORPOSITION(ID) VALUES (?)");
for ( int i=1; i<=10; i++ ) {
pstmt.setInt(1, i);
pstmt.executeUpdate();
}
pstmt.close();
// Selecting data
System.out.println("Selection data from table 'CURSORPOSITION'");
Statement stmt = connect.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
stmt.setFetchSize(5);
ResultSet rs = stmt.executeQuery(
"SELECT ID FROM CURSORPOSITION ORDER BY ID");
System.out.println("Setting cursor to last row");
if ( !rs.last() )
System.out.println("Setting cursor to last row failed!");
System.out.println("CURSOR POS: " + rs.getRow() +
", CONTENT: " + rs.getObject(1));
// Dropping table
System.out.println("Dropping table 'CURSORPOSITION'");
connect.createStatement().executeUpdate(
"DROP TABLE CURSORPOSITION");
} catch (Throwable t){
t.printStackTrace();
}
}
}
The output looks like:
Driver version: package com.sap.dbtech.jdbc, "SAP DB JDBC Driver", "SAP AG",
"7.3.0 Build 023-000-085-131"
Creating table 'CURSORPOSITION'
Inserting data to table 'CURSORPOSITION' (10 rows)
Selection data from table 'CURSORPOSITION'
Setting cursor to last row
CURSOR POS: -1, CONTENT: 10
Dropping table 'CURSORPOSITION'
Any hints?
Regards,
Kolja
Mit besten Gruessen
Kolja Kleist (Senior Developer)
____________________________________
MediaTransfer AG
Netresearch & Consulting
Rothenbaumchaussee 38, 20148 Hamburg
Tel: (040) 669 625 16
Fax: (040) 669 625 29
URL: http://b2b.mediatransfer.de
____________________________________
_______________________________________________
sapdb.general mailing list
[EMAIL PROTECTED]
http://listserv.sap.com/mailman/listinfo/sapdb.general