How to create a database trigger that log a row change to another table in H2?
In MySQL, this can be done easily:
CREATE TRIGGER `trigger` BEFORE UPDATE ON `table`
FOR EACH ROW BEGIN
INSERT INTO `log`
(
`field1`
`field2`,
...
)
VALUES
(
NEW.`field1`,
NEW.`field2`,
...
) ;
END;
Declare this trigger:
Implementing the trigger with Java/JDBC:
Implementing the trigger with jOOQ:
Since you added the jOOQ tag to the question, I suspect this alternative might be relevant, too. You can of course use jOOQ inside of an H2 trigger: