views:

38

answers:

2

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!

+2  A: 

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.

Stephen C
A: 

It depends on the database you are using, as some allow you to run code that would allow you to make a call to a server, through a trigger, but, then you take a performance hit on these modifications, so you would want to use a webservice that doesn't send any information back to, to limit the performance hit.

It also depends on if you are using a server, as then you could use AspectJ to monitor any of the update queries.

James Black