Solved

call an external command (such as java program but without gui stuff) from a trigger or stored procedure...

Posted on 2004-10-13
5
1,135 Views
Last Modified: 2008-03-17
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,
0
Comment
Question by:Lynnzi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12304662
So what's wrong with xp_cmdshell?
0
 
LVL 24

Accepted Solution

by:
Joe Woodhouse earned 500 total points
ID: 12304810
There's no great answer to this.

xp_cmdshell is probably the easiest to program, but it is not transactional - it's not guaranteed to work. It also has a lot of moving parts - it relies on the external XP Server, which then calls your sender program.

If all you want is to send a message to a particular port, you could look into sp_sendmsg. It sends a varchar(255) to any port on any IP address via UDP. It also isn't guaranteed or transactional, but at least it doesn't rely on the XP Server. It might also allow you to dispense with your AA program for fewer moving parts.

Some caveats - sp_sendmsg is not available for ASE on Windows, and you must first configure "allow sendmsg" to 1 using sp_configure.

If you were willing to spend money on this, you could buy Sybase's XFS premium feature for ASE (only in 12.5+), which allows you to build a proxy table on a directory. You could then have the trigger insert a row to this proxy table, which would result in a file being created in the directory. This still isn't a great answer for you as it requires a paid license and still requires polling, but polling is much cheaper at the operating system level than within the database. I know of a factory floor that submits print jobs in this way.
0
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12307996
You can also create a custom extended stored procedure as a DLL. Search on "Extended stored procedures" if you're interested in this option.
0
 

Author Comment

by:Lynnzi
ID: 12313977
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.
0
 

Author Comment

by:Lynnzi
ID: 12313982
Forgot to say, Thanks ALL for your quick response.  
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article was originally published on Monitis Blog, you can check it  here .   Some years back, I worked as the CTO.  During my tenure, I had a head of IT support reporting to me.  He did his job quite well and had a commendable sense of duty…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question