Question

I am usingoracle.jdbc.dcn.DatabaseChangeListener to record inserts/updates/deletes to a table. For inserts, I can keep track of the rowids. However, I am having a problem with updates and deletes.

For updates, I am looking for a way to find out the value of the row/column before the update as made.

For deletes, I get the rowid that was deleted, but that is all I get. I would like some sort of ability to track which row was deleted.

I am setting the properties using oracle.jdbc.OracleConnection.

Properties changeNotifProps = new Properties();
changeNotifProps.put(OracleConnection.DCN_IGNORE_DELETEOP,"false");             
changeNotifProps.put(OracleConnection.DCN_IGNORE_INSERTOP, "false");
changeNotifProps.put(OracleConnection.DCN_IGNORE_UPDATEOP , "false");
changeNotifProps.put(OracleConnection.DCN_NOTIFY_CHANGELAG , "0");
changeNotifProps.put(OracleConnection.DCN_NOTIFY_ROWIDS , "true");
changeNotifProps.put(OracleConnection.NTF_LOCAL_HOST , <hostname>);
changeNotifProps.put(OracleConnection.NTF_LOCAL_TCP_PORT , "7115");
return changeNotifProps;

Is there some sort of property I can set to detect the previous value of the rows?

EDIT: I forgot to mention that I am doing this on hundreds of tables. I can't add triggers/tables to log the change. I need to record all the changes in the JVM.

Was it helpful?

Solution

Create an audit table and use an AFTER INSERT UPDATE DELETE trigger to populate it. I like to log the key (you could log the ROWID here), the time and date, the user, the SQL verb (INSERT, UPDATE, DELETE) and the appropriate values (use the NEW values on INSERT and UPDATE, use the OLD values when logging a DELETE). Given this you should be able to retrieve your values from the audit table.

Share and enjoy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top