I am trying to execute my java application once a record is inserted, deleted or update into a database table. For that sake, I am planning to write a Trigger which will be called while inserting. My question is that, will I be able to call a java application from this trigger?
-
I don't think that is possible. Try different approach - eg. java app listens to changes on db and does required work if specific event appears.itwasntme– itwasntme2018-06-23 18:47:43 +00:00Commented Jun 23, 2018 at 18:47
-
java app listens to a particular record is inserted/modified/deleted in a table of a database?Ajay Takur– Ajay Takur2018-06-23 19:02:46 +00:00Commented Jun 23, 2018 at 19:02
1 Answer
While Python and Perl, among others, have a PL equivalent that can be written within an SQL function (albeit with sometimes considerable overhead), Java does not. Even if the Java app could be launched via command line or something after a trigger, the overhead in launching the JVM alone would be a performance disaster.
I would recommend looking into having Postgres emit notifications via notify. This would let you send a payload (although there are size limitations) that can be listened for by a client (that client could be your Java app, or an intermediate program that performed some additional ETL to get it ready for your app). This should allow for the data to be served up and processed in a performant way.