2

I have a table recording trade data . Whenever a record is inserted in this table I would like to send a mail with the details of that record.

Any pointers on how that can be done. I believe working on a trigger that is fired on insert on that table is the way to go but am not sure about what to do further for sending the mail .

Imp to note is that since its a trade table the performance of the query or the database should not be impacted.

Viren Pushpanayagam
  • 2,397
  • 6
  • 35
  • 39
Sandy
  • 21
  • 2

2 Answers2

2

Here you have an explanation how to send a mail from Java: How do I send an e-mail in Java?

Now, first try to find a method call responsible for saving that object in database. Then add email sending code to the method.

Put that code outside, more specifically after the transaction - you can't rollback a sent email anyway. Just make sure you get a response from database that transaction was successful.

And please note that by sending an email for each new record you may easily bury the email inbox with these messages.

Community
  • 1
  • 1
Goran Jovic
  • 9,418
  • 3
  • 43
  • 75
1

You could make some background task that looks at the table at a regular interval and sends emails for any new records it finds. New records could be detected efficiently by using a serial or a timestamp column.

Often best to run this task from some scheduler that starts it every n minutes.

Eelke
  • 20,897
  • 4
  • 50
  • 76