• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need to Invoke a Java Program from a trigger

 
Bhanu Priya
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bhanu Priya
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Oracle 10 g database and I am not sure whether it supports java or not.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul, but I want to know what is the solution if I am using Oracle 9? Please reply.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, Oracle 9i also supports Java. And it contains the UTL_SMTP package.
 
Charbel Keyrouz
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The SMTP service appears not to be available.
 
Bhanu Priya
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic