I am running a simple update statement in my java code to an oracle database (JDBC call) and it updates when record is found but when record doesn't exist i get " java.sql.SQLException: ORA-01002: fetch out of sequence" exception. Here is my code, why exception? Where should I improve it. Code sample would be very helpful.
public String preformUpdate(String someValue){
ResultSet rs;
String result = "Update failed record not found.";
StringBuffer sb = new StringBuffer();
try{
conn = DBConnect.getInstance().dbOracleConnect();
StringBuffer sbUpdate = new StringBuffer();
sbUpdate = new StringBuffer("UPDATE sometable ");
sbUpdate.append("SET value1 = ? ");
sbUpdate.append("WHERE value2 = ?" );
ps = conn.prepareStatement(sbUpdate.toString());
ps.setString(1, "0");
ps.setString(2, someValue);
rs = ps.executeQuery();
if (rs.next()){
result = "Value updated";
}
}
catch (Exception e){
e.printStackTrace();
}
finally{
JDBCHelper.close(cs);
JDBCHelper.close(conn);
}
return result;
}