Search code examples
javadatabaseconnection

Intercept all Database call in Java


I want to intercept insert query in my database and want to change its insert value

for example, if the user inserts a value name = amitrai in a database, I want to change the value from amitrai to &^&WQWSAKJSJA and then store.

overall I want intercept to execute the query in JDBC connection.


Solution

  • Use Trigger on insert as @Mureinik suggested

    for example for table yourtable insert:

    CREATE OR REPLACE TRIGGER NameChange
        BEFORE INSERT
        ON yourtable
        FOR EACH ROW
    BEGIN
        IF :new.name = 'amitrai'
        THEN
            :new.name := '&^&WQWSAKJSJA';
        END IF;
    END;