java.sql.SQLException: ORA-01002: fetch out of sequence on XATransaction java.sql.SQLException: ORA-01002: fetch out of sequence on XATransaction oracle oracle

java.sql.SQLException: ORA-01002: fetch out of sequence on XATransaction


The code is incomplete, so I can only guess:

  • the cursor was closed and you tried to fetch again
  • you did select for update and committed and then tried to fetch the next row.


Is your connection set to auto commit? A fetch across a commit or rollback is likely to cause this exception.

I also noticed that your SQL isn't surrounded by begin/end as in the Oracle docs or {} as in this example and the Oracle Javadoc.


To make certain whether when hitting exception all the rows are processed

Modify the below code to include a counter i to get processed rows and find actual count of rows

 int i=0;  try{ while (rs.next()) {            Interval interval = new Interval(rs.getLong("from_no"), rs.getLong("to_no"));            intervals.put(interval, rs.getString("market_code"));            i=i+1;        }}catch (Exception e){ Logger.getLogger(getClass().getName()).log(Level.FINE, "the total rows processed"+ i); Statement stmt = null; String query = "select count(1) count_rows                                  from market_codes";    stmt = con.createStatement();    ResultSet rs1 = stmt.executeQuery(query);    rs1.next();    String countRows = rs1.getString("count_rows");    Logger.getLogger(getClass().getName()).log(Level.FINE,"Actual count of rows"+ countRows); }