Search code examples
javadatabaselisteners

How to detect database events with, for example, Java


Is there a way to detect database events, e.g. insert, update and delete, comparable to file access monitors like JNotify (can detect read, create, modify of files and directories)?

Looking for something like database event listeners because I don't want to do polling.

Thanks!


Solution

  • In general no. AFAIK, no such facility exists in JDBC or in the SQL standards.

    It might be possible for certain databases / configurations using database specific functionality. For example, if the database can be configured to run arbitrary Java code in a trigger, you might be able to get it to send an event into a pubsub system that will deliver it to your application code.

    But I think it would be better to modify your application code-base to generate the events itself.