1

Initially I had given:

 Statement replystmt = connection.createStatement;

which I changed to

Statement replystmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

ResultSet replyMessage = replystmt.executeQuery("SELECT * from REPLYMAIL where PARENTMESSAGEID = '" + parentMessage.getString("MESSAGEID") + "'");

I am still getting the following error:

        java.sql.SQLException: Invalid operation for forward only resultset : isLast
            at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
            at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
            at oracle.jdbc.driver.OracleResultSetImpl.isLast(OracleResultSetImpl.java:390)
            at inbox.InboxReader.getImportance(InboxReader.java:249)
            at inbox.InboxReader.main(InboxReader.java:39)

Edited:

static long getImportance(String username) throws Exception
    {
        Connection connection = connectToDatabase();
        Statement parentstmt = connection.createStatement();
        ResultSet parentMessage = parentstmt.executeQuery("SELECT * from MAIL");
        long time1 = 0, sign = 0;

        while(parentMessage.next())
        {
            System.out.println("Parent message : " + parentMessage.getString("MESSAGEID"));
            int c = 0, evenc = 0;
            String j = "";

            Statement replystmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            //stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)

            ResultSet replyMessage = replystmt.executeQuery("SELECT * from REPLYMAIL where PARENTMESSAGEID = '" + parentMessage.getString("MESSAGEID") + "'");

            if(!(parentMessage.getString("SENDERNAME").contains(username)))   // When user receives a message first
            {
                while(replyMessage.next())
                {
                    if(c==0)   // for calculating the time between his reply time - message received time  
                    {
                        time1 = replyMessage.getTimestamp("SENDDATE").getTime() - parentMessage.getTimestamp("RECEIVEDATE").getTime();
                        System.out.println("IF time in if c=0, " + time1);
                        c++;
                        sign = 1; 
                    }
                    else   
                    {

                        evenc++; 
                        if(sign == 1) {
                            sign = -1;
                            j = "RECEIVEDATE";
                            System.out.println("IF receivedate : " + replyMessage.getTimestamp(j).getTime());
                        }
                        else if(sign != 1) {
                            sign = 1;
                            j = "SENDDATE";
                            System.out.println("IF senddate : " + replyMessage.getTimestamp(j).getTime());
                        }   

                        if(replyMessage.isLast() && (evenc%2)!=0) {
                            System.out.println("IF skip");
                        }
                        else {
                            time1 = time1 + (sign * replyMessage.getTimestamp(j).getTime());
                        }
                        System.out.println("IF time in if c>0 , "+time1);
                    }
                }
            }
            else {             // When user sends a message first
                sign = -1;
                while(replyMessage.next()) {
                    evenc++;
                    if(sign == 1) {
                        sign = -1;
                        j = "RECEIVEDATE";
                        System.out.println("ELSE receivedate : " + replyMessage.getTimestamp(j).getTime());
                    }
                    else {
                        sign = 1;
                        j = "SENDDATE";
                        System.out.println("ELSE senddate : " + replyMessage.getTimestamp(j).getTime());
                    }   

                    if(replyMessage.isLast() && (evenc%2)!=0) {
                        System.out.println("ELSE skip");
                    }
                    else {
                        time1 = time1 + (sign * replyMessage.getTimestamp(j).getTime());
                    }
                    System.out.println("ELSE time in if c>0 , "+time1);
                }
            }   
        }
        connection.close();
        return time1;
    }

How do I fix this?

Thanks!

1
  • Can you post the code which is throwing this exception? Commented Nov 7, 2011 at 2:42

1 Answer 1

1

This link says that the isLast() method may not be supported by Oracle for stored procedure ResultSet reading. As a work around you can count the number of rows returned first. And then know which row is the last when you actually loop through all the rows during processing.

Sign up to request clarification or add additional context in comments.

2 Comments

Do you know how performance is? Wouldn't this pull all rows into memory to count them? Or do you mean to use a select count(*) query for this?
@HeikoRupp I would think the ResultSet will be in memory. So I don't think my solution will require significant amount of additional memory. But it will require two iterations over the ResultSet. This additional iteration maybe better than two queries (SELECT COUNT(*) and main query). Makes sense?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.