aspose file tools*
The moose likes JDBC and the fly likes Need to Invoke a Java Program from a trigger Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Need to Invoke a Java Program from a trigger" Watch "Need to Invoke a Java Program from a trigger" New topic
Author

Need to Invoke a Java Program from a trigger

Bhanu Priya
Greenhorn

Joined: Aug 12, 2009
Posts: 7
Hi All,

I have a requirement whenever a request is raised which comes as a new row in the database, i need to send a SMS and an email to the users. I wrote a trigger on my input table to send the SMS which is just a insert query into the SMS table. Now i also have to send an email. Please help me out how can i send an email from trigger. Is there is any way of invoking a Java Program from a Trigger?

Thanks in advance.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Yes, if your database supports Java. Does it?

If it doesn't some database include mechanisms to make calls to the OS shell. Also some database support the sending for notifications without the need to write a Java program to do it. Which database are you using?

If your database supports none of these things you could poll the table from your Java program. OK there will be a delay, but email is asynchronous so a delay is acceptable.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Bhanu Priya
Greenhorn

Joined: Aug 12, 2009
Posts: 7
I am using Oracle 10 g database and I am not sure whether it supports java or not.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Oracle 10 does support Java so you could go down the Java route. Alternatively you could use the procedures in the UTL_SMTP package to do much the same.
Bhanu Priya
Greenhorn

Joined: Aug 12, 2009
Posts: 7
Thanks Paul, but I want to know what is the solution if I am using Oracle 9? Please reply.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Well, Oracle 9i also supports Java. And it contains the UTL_SMTP package.
Charbel Keyrouz
Ranch Hand

Joined: Jun 10, 2005
Posts: 46
Another solution would be to insert the message that you want to send with the all the necessary details and make a java scheduler that checks the content of this table from time to time and handles every record with the way it should.

This solution is more universal since not all databases support java.
Bhanu Priya
Greenhorn

Joined: Aug 12, 2009
Posts: 7
Thanks Charbel,

Anyhow i tried using utl_smtp package, but i am getting the runtime error while using open_connection function.

ORA-29278: SMTP transient error: 421 Service not available
ORA-06512: at "SYS.UTL_SMTP", line 21
ORA-06512: at "SYS.UTL_SMTP", line 97
ORA-06512: at "SYS.UTL_SMTP", line 139

I am able to send email successfully with the same server from java. Please help me out.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

The SMTP service appears not to be available.
Bhanu Priya
Greenhorn

Joined: Aug 12, 2009
Posts: 7
But, I am able to send mail from the same server from Java. Not able to understand whats wrong when I am trying with the Database.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need to Invoke a Java Program from a trigger