Lynnzi
asked on
call an external command (such as java program but without gui stuff) from a trigger or stored procedure...
What i need for my project is: when a sybase table is changed (insert/update etc), the trigger calls an external java program AA to notify my another java program BB about the changes. The program AA only does 1 thing: sending out an int value to a certain predefined socket, while program BB is waiting there on the socket for incoming message.
The trigger is like:
create trigger book_u_trig
as
....
if update(title)
exec xp_cmdshell "AA 9012"
return
where "9012" is the parameter to program AA and it is also the socket number that AA is going to send out an integer value through.
On the same machine (as Sybase server), i have already run another program BB as
java BB 9012
which means BB is listening to any incoming message on socket 9012.
The background of such a requirement: my project requires to know "realtime" that a table has been changed, so further actions might be taken. It will be inefficient for my project to poll the sybase table at short intervals of time period; instead, i want the table itself to notify my program about the changes.
Thanks,
The trigger is like:
create trigger book_u_trig
as
....
if update(title)
exec xp_cmdshell "AA 9012"
return
where "9012" is the parameter to program AA and it is also the socket number that AA is going to send out an integer value through.
On the same machine (as Sybase server), i have already run another program BB as
java BB 9012
which means BB is listening to any incoming message on socket 9012.
The background of such a requirement: my project requires to know "realtime" that a table has been changed, so further actions might be taken. It will be inefficient for my project to poll the sybase table at short intervals of time period; instead, i want the table itself to notify my program about the changes.
Thanks,
So what's wrong with xp_cmdshell?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can also create a custom extended stored procedure as a DLL. Search on "Extended stored procedures" if you're interested in this option.
ASKER
AA is a java class on Sybase server machine, on which the classpath has been set up proprely.
Previously, when i simply use "exec xp_cmdshell java AA 9012" in the trigger, the trigger just hangs. Thus i posted the message to Expert Exchange.
Just realized that i need to add the classpath into the command within xp_cmdshell as it seems the XP server does not look up in environment variable "CLASSPATH" at all.
So it works now with quite satisfactory response time:
create trigger book_u_trig
as
....
if update(title)
exec xp_cmdshell "javaw -classpath c:\j2re1.4.2\bin\;c:\hooks \classes AA 9012"
return
Note that no spaces are allowed in the classpath.
Previously, when i simply use "exec xp_cmdshell java AA 9012" in the trigger, the trigger just hangs. Thus i posted the message to Expert Exchange.
Just realized that i need to add the classpath into the command within xp_cmdshell as it seems the XP server does not look up in environment variable "CLASSPATH" at all.
So it works now with quite satisfactory response time:
create trigger book_u_trig
as
....
if update(title)
exec xp_cmdshell "javaw -classpath c:\j2re1.4.2\bin\;c:\hooks
return
Note that no spaces are allowed in the classpath.
ASKER
Forgot to say, Thanks ALL for your quick response.