I wanted to know if it is possible to create a trigger in a mysql database that calls/runs a java class from a java desktop application.How can one go about doing this?any help would be very appreciated...
MySQL is a RDBMS which doesn't know about Java or any other language for that matter. What exactly you are trying to accomplish here? You may need to do the reverse? Or can't you use a procedure/trigger in the MySQL itself to do this?
Different RDBMS know about different languages for triggers. E.g. you can write Java in Oracle.
Joined: Apr 20, 2011
ok lemme give more details.
there are two java systems that are communicating with the mysql database. One inserts data and the other only views data. How it should work is that when the first system inserts some data into the database the second system should display the information that was inserted. I was trying to do this by placing a trigger where when there is an insert into the database a method in the second system should be called that reads the data and then displays it.
Im not sure if this is the best approach towards this.
Hauke Ingmar Schmidt
Joined: Nov 18, 2008
So basically you want to notify another system when changes in the database appear. While there may be database systems that allow this (IIRC MS SQL Server has a kind of change notification) it is not a good idea to trigger a change from a system lower in the layer hierarchy to a higher system. You certainly don't want your database to be dependent on response times of another system. But in general this would be independent of the language the trigger is written in; if you could call a webservice in a trigger you just could use this. You can't, in MySQL, as far as I know, for the very same reason.
You need a business layer, another app, that controls database access and notifies other systems. Sounds like an ESB could get handy here. Or some other means of distributed messaging. You certainly don't want the whole system to hang just because the notification for the view fails.
If it is a really, really tiny system, that will not be extended and reliance is not important, you could just let the input system notify the view system. No, don't do this. Don't go to the dark side.