Java run by MySQL trigger

Though not a standard feature this is very well possible with MySQL. You can use the SELECT .. INTO OUTFILE statement from inside the trigger to write to a named pipe (Windows) or memroy filesystem (Linux). Both of those can easily be monitored from Java code (or any other code for that matter). Using this technique you will avoid polling and because no actual disk access takes place either you will have good performance.

I have written a Java package for this actually so I'm 100% sure it is possible and performs well. Unfortunately I am not allowed to share my efforts here (my previous answer was deleted by a moderator) so you will have to code it yourself, sorry.


A direct answer: no you can't call a java method from a mysql trigger. If you had an oracle database you could, but not mysql.

To do what you want to do with mysql you can

  • make the code that updates the database also notify the swing application. Or you can
  • make the trigger accumulate data on pending operations in a separate table that you read periodically from the swing app.