You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by "Bit Runner..." <bi...@katamail.com> on 2007/10/27 14:10:34 UTC

Error: Invalid cursor state - no current row.

Hello,
i have the database with two tables Opzioni, Preventivi.

This is my code;

public class DerbySample {
 
  public static void main(String args[]) {
     // esempio collegamento a derby con modifiche
     try {
        
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
        String connectionString = 
"jdbc:derby:/Users/harlock/Documents/soft/EsempiJava_15/dati;create=false";
        Connection con = DriverManager.getConnection(connectionString, 
"", "");
        String sql = "select * from preventivi where prvID = 1";
        ResultSet rsPreventivi = 
con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
ResultSet.CONCUR_UPDATABLE).executeQuery(sql);
        rsPreventivi.next();
        sql = "select * from opzioni";
        //----
        ResultSet rsOpzioni = 
con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
ResultSet.CONCUR_READ_ONLY).executeQuery(sql);
        while (rsOpzioni.next()) {
           System.out.println(rsOpzioni.getString("opzUtente"));
        }
        rsOpzioni.close();
        //----
        rsPreventivi.updateString("prvUtente", "fran");
        rsPreventivi.updateRow();
        rsPreventivi.close();
        System.out.println("bye bye");
     } catch (Exception ex) {
        System.out.println(ex.toString());
     }

  }
}

Run my sample program i receive the error: Invalid cursor state - no 
current row.
If comment the line;
        ResultSet rsOpzioni = 
con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
ResultSet.CONCUR_READ_ONLY).executeQuery(sql);
        while (rsOpzioni.next()) {
           System.out.println(rsOpzioni.getString("opzUtente"));
        }
        rsOpzioni.close();

my program work correctly!!!

Why? I don't understand!!!
thans.

Re: Error: Invalid cursor state - no current row.

Posted by Knut Anders Hatlen <Kn...@Sun.COM>.
"Bit Runner..." <bi...@katamail.com> writes:

> Exact: I have put setAutoCommit(false) and all it works correctly!!! :-))))
>
> Thanks
>
> PS: an other question: but in AutoCommit true the every instruction
> sql is executed in one isolated transaction. And therefore why it gave
> error to me? In theory it would have to give it with AutoCommit false.

Your two SQL statements weren't executed in different transactions
(there's only one active transaction for each java.sql.Connection), so
when rsOpzioni was closed, the transaction in which both rsOpzioni *and*
rsPreventivi were executed, was committed.

-- 
Knut Anders

Re: Error: Invalid cursor state - no current row.

Posted by "Bit Runner..." <bi...@katamail.com>.
Exact: I have put setAutoCommit(false) and all it works correctly!!! :-))))

Thanks

PS: an other question: but in AutoCommit true the every instruction sql 
is executed in one isolated transaction. And therefore why it gave error 
to me? In theory it would have to give it with AutoCommit false.

Bryan Pendleton ha scritto:
>> Run my sample program i receive the error: Invalid cursor state - no 
>> current row.
>> If comment the line;
>>        ResultSet rsOpzioni = 
>> con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
>> ResultSet.CONCUR_READ_ONLY).executeQuery(sql);
>>        while (rsOpzioni.next()) {
>>           System.out.println(rsOpzioni.getString("opzUtente"));
>>        }
>>        rsOpzioni.close();
>>
>> my program work correctly!!!
>
> Perhaps your connection is in "auto-commit" mode, and the execution of
> the inner query is causing a commit, which is closing the outer query's
> result set as well?
>
> Does the behavior change if you call con.setAutoCommit(false) at the
> start of your program?
>
> thanks,
>
> bryan
>
>


Re: Error: Invalid cursor state - no current row.

Posted by Bryan Pendleton <bp...@amberpoint.com>.
> Run my sample program i receive the error: Invalid cursor state - no 
> current row.
> If comment the line;
>        ResultSet rsOpzioni = 
> con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
> ResultSet.CONCUR_READ_ONLY).executeQuery(sql);
>        while (rsOpzioni.next()) {
>           System.out.println(rsOpzioni.getString("opzUtente"));
>        }
>        rsOpzioni.close();
> 
> my program work correctly!!!

Perhaps your connection is in "auto-commit" mode, and the execution of
the inner query is causing a commit, which is closing the outer query's
result set as well?

Does the behavior change if you call con.setAutoCommit(false) at the
start of your program?

thanks,

bryan