Trying to use the .previous() method on a UCanAccess ResultSet

时间:2015-07-28 15:44:55

标签: java jdbc ucanaccess

I am working on batching information from Facebook. I have decided that the best way to get to the result i want is to have 2 loops , while both are about if my resultset has .next() ....

The problem is that ResultSets don't have a hasNext() method but only next(). So I've tried to move back after the first .next() method using .previous() and I get a "feature not supported" error.

So I've tried again just after the second .next() and it says the same thing....

It seems you cannot use .previous() under UCanAccess.

The exception is -

net.ucanaccess.jdbc.UcanaccessSQLException: feature not supported
at net.ucanaccess.jdbc.UcanaccessResultSet.previous(UcanaccessResultSet.java:933)

code part -

int i = 1;
        try {
        idsLoop:while(rs.next()){
            if(i==1){
                rs.previous();
            }
            if(i<50){
                idsForRequest.add(rs.getString("Expr1"));
                i++;
                }
                else{
                    i=1;
                    break idsLoop; 
                }

BTW if anyone is wondering why I'm doing it like that , is because I don't want to batch more than 50 pages at a time.

1 个答案:

答案 0 :(得分:2)

JDBC Statement objects default to ResultSet.TYPE_FORWARD_ONLY under UCanAccess (and most, if not all, JDBC drivers) so rs.previous() will fail if you do something like

try (Statement st = conn.createStatement()) {
    try (ResultSet rs = st.executeQuery(sql)) {
        // ...
        rs.previous();  // <- error

However, if you specify a scrollable ResultSet when you create the Statement object ...

try (Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)) {
    try (ResultSet rs = st.executeQuery(sql)) {
        // ...
        rs.previous();  // <- no error

... then rs.previous() will work.