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

This is a discussion on Error: Invalid cursor state - no current row. - Apache ; 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 ...

+ Reply to Thread
Results 1 to 4 of 4

Error: Invalid cursor state - no current row.

  1. Default 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.


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

    > 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



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

    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
    >
    >




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

    "Bit Runner..." <bitrunner-WmCXPOaMvLBWk0Htik3J/w@public.gmane.org> 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


+ Reply to Thread