1

Please tell me is it possible to call a java method or a struts action class when a record is inserted in mysql database Actuall my problem is i have 2 databases(both are mysql databases namely db1 and db2) running in two different locations.I need communication between them.When a record is inserted in X table in db1 at the same time some data must be insert in Y table in db2 depending up on the data inserted in db2 some data must be inserted in Z table in db1.

Actuall my project is patient care project for a group of patients one care taker is there
for each and every patient one embeded button is there. the mapping between the patient details and the embeded button and the corresponding care taker is there in db2 database when the patient pressed the embeded button embeded information is inserted in db1 and inorder to send a mobile message to care taker i haveto get the data from db2 depending up on the embeded information inserted in db1 as patient and caretaker mapping is in db2

the businesslogic communicate with db1 iswritten in vc++

the businesslogic communicate with db2 iswritten in java

so i need communication between db1 and db2

technologies used

java,struts 1.2

database : mysql

2
  • The short answer is Yes. As long as you have structured your business logic accordingly. Where is the insert command coming from? Commented Jul 4, 2011 at 11:40
  • 1
    You mean if record is inserted directly to db outside of your app? Then the only way I think is to periodically query database. Commented Jul 4, 2011 at 11:46

4 Answers 4

3

I don't think it it is possible to trigger java code actively from db insert. What we do is the opposite:

  • when an insert occurs, we write the rowid to a dedicated table
  • we have a Java job that runs regularly and checks that table for new entries

You should not do any such thing in a web context, so forget struts in this context!

Sign up to request clarification or add additional context in comments.

Comments

0

You can have a java process periodically query the table to check for new records. A better solution would be to have a database trigger perform the business logic you need (though you can't call the struts action directly). If you can provide more detail on what business logic you need performed after the row is inserted, we can maybe provide a much cleaner design.

Comments

0

Even though it's possible to use another Struts action (As it's a simple POJO class that can be instantiated like SomeAction action = new SomeAction()) I would not recommend it for few reasons:

  • You will have to pass various Struts configurations to the action in order to work.
  • Handle the ActionForward response.

My suggestion is to put your business logic in a service that you can either pass the same data to 2 databases or have strategy that understands that the data needs to be recorded to 2 databases.

Comments

0

Here's an extension for MySQL (UDF) that allows execution of other programs from MySQL.

It should be relatively straightforward how to use it. I don't know ins and outs of your application, but you can create a trigger that calls a program and passes certain parameters you require to establish your db communication.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.