2

In my requirement need to Invoke java method or webservice while a record is insert or update in to a Table.

I am using Postgres (9.5) Database , How can I invoke the java method?

Rajesh
  • 85
  • 1
  • 2
  • 10
  • what is inserting a record into the DB? – Scary Wombat Apr 04 '18 at 07:12
  • I'm not sure "invoke the Java method" even makes sense, because Postgres does not run on a JVM. Postgres may have some extensions which can make an API call, but even then you'd be calling some Java webservice, and not Java directly. – Tim Biegeleisen Apr 04 '18 at 07:14
  • So where is that "Java method" located? Is that exposed as a web service in an application server? Do you only have a JAR file? –  Apr 04 '18 at 07:14
  • Possible, but involves plenty of trickery: https://stackoverflow.com/questions/21632243/how-do-i-get-asynchronous-event-driven-listen-notify-support-in-java-using-a-p – Kayaman Apr 04 '18 at 07:15
  • @TimBiegeleisen: well there is, PL/Java but that is not a road I would like to take. For one it's not actively maintained but more importantly it starts one JVM for **every** connection which is a huge overhead. –  Apr 04 '18 at 07:16
  • @a_horse_with_no_name Sounds like it. But read the very first comment, I'll bet there is a workaround here which doesn't require calling Java from Postgres. – Tim Biegeleisen Apr 04 '18 at 07:16
  • Use AOP to call another method inside your java program whenever the method call to persist data happens. – BarathVutukuri Apr 04 '18 at 07:22
  • @a_horse_with_no_name , web service is in application server – Rajesh Apr 04 '18 at 07:27
  • This is a seriously bad idea. It will slow down your transactions unpredictably. Use some queuing or messaging technique and an asynchronous worker process. – Laurenz Albe Apr 04 '18 at 07:29
  • So you need to make a HTTP call to an application server, not "call a java method" –  Apr 04 '18 at 07:29
  • yes, I need to invoke the service. How can I achieve this one. – Rajesh Apr 04 '18 at 07:33
  • I seriously recommend looking at the link I gave in my comment. For the sheer interest value, not really as a solution for this question. – Kayaman Apr 04 '18 at 07:33
  • yes @Kayaman, I'll refer this link. – Rajesh Apr 04 '18 at 07:37
  • I was actually suggesting that to the other commenters. It is quite interesting what you can do with Postgres when you switch to a different driver. – Kayaman Apr 04 '18 at 07:42

0 Answers0