-1

I want to get the results from my query. I get the ResultSet with next() = true. But when I do getString() I get the following error: "Incorrect cursor status: indicated cursor is not positioned in a row for UPDATE, DELETE, SET, or GET statement:; Current position of the query result is after the last record"

My query returns 1 row of results.

My code is:

ResultSet rs = ejecutarSentencia("SELECT ITEM "
                    + "FROM STORE"
                    + "WHERE REF = '"+ref+"';");

            if (rs.next()) {
                String item = rs.getString(rs.findColumn("ITEM"));
            }

The error message is: "net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::4.0.4 Incorrect cursor status: indicated cursor is not positioned in a row for UPDATE, DELETE, SET, or GET statement:; Current position of the query result is after the last record"

when I execute the line:

String item = rs.getString(rs.findColumn("ITEM"));
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
Adriana_0_0
  • 85
  • 2
  • 7
  • Please [edit] your question to include a [mcve]. The current code in your question simply cannot produce the result you describe. No call to `rs.next()` that returns `true` will leave the ResultSet positioned after the last record. – Gord Thompson Sep 09 '19 at 13:44

1 Answers1

0

That's how i've done it after reading online. Make sure to initialise the driver before connecting

try 
{
    Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
}
catch(ClassNotFoundException cnfex) 
{
    System.out.println("Problem in loading or "
    + "registering MS Access JDBC driver");
    cnfex.printStackTrace();
}

Then also make sure you execute your query.

public String[] YourFonction(String anyParameters)
{
    String[] infoToreturn = new String[3];
    String info1;
    String info2;
    String info3;

    Statement st;
    final String ACCESS_SELECT = "SELECT x,y,z FROM yourTable WHERE something = '" + anyParameters + "'";
    try
    {
        st = conn.createStatement();

        ResultSet rs = st.executeQuery(ACCESS_SELECT);
        while (rs.next()) 
        {
            info1 = rs.getString(1);
            info2 = rs.getString(2);
            info3 = rs.getString(3);
        }
    }
    catch (SQLException e)
    {
        e.printStackTrace();
    }

    infoToreturn[0] = info1;
    infoToreturn[1] = info2;
    infoToreturn[2] = info3;
    return infoToreturn;
}

Hope it helps. Reference site : https://www.benchresources.net/jdbc-msaccess-database-connection-steps-in-java-8/

Notes:

  • The code above has not been compiled nor tested and is posted more to show concepts not to copy and paste as a direct solution.