Let me be clear with the problem – I have a query used to update a few columns in an Oracle table:
UPDATE MED_COM_MAPPER_CMDS SET STATUS = ?, OUTAGE_ID = ? WHERE CMD_ID = ?
I want to conditionally not update the OUTAGE_ID column value table unless I have a particular value in the STATUS column. How can I implement this within the same method as shown below? Changes to the method are acceptable, but not too many. Is it not possible to do this in the same method shown by the below lines of code ?
Connection connection = DatabaseUtil.getConnection();
preparedStatement.setInt(1, Integer.parseInt(status));
// On a condition, how can i avoid updating this column value.
// That means keep intact what it is in the DB.
preparedStatement.setString(2, outage_id);
preparedStatement.setString(3, cmd_id);
int i = preparedStatement.executeUpdate();
connection.commit();
This is to just to make it simple. It can be done by overriding the query or the method or by if conditions with increment of index value.
Hope I’ve been clear.
How about change the update statement, something like:
If status = ‘X’ (the existing status value that is), then update outage_id with new_val, else keep existing outage_id.