If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Calling a shell script from within a DB2 9.1 stored procedure

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-28-08, 10:59
jekyll jekyll is offline
Registered User
 
Join Date: Oct 2008
Posts: 4
Calling a shell script from within a DB2 9.1 stored procedure

Hi guys,

I am trying to translate some functionality from Oracle to DB2 9.1 and was wondering if any of you DB2 gurus out there could give me a hand. I need to call a command line application from within a DB2 stored procedure and wait for the application to finish before the stored procedure continues. In Oracle we call a Java procedure from within an Oracle stored procedure to achieve this and I was wondering if the same is possible within DB2?

I have been doing some reading up on this and it looks like it may be possible to do this using SQLJ, however finding information on how exactly to do this is proving to be very difficult. If you could reply with maybe a very basic example of how this could be achieved (some sort of Hello World example if possible) I would very much appreciate it.

Thanks in advance....
Reply With Quote
  #2 (permalink)  
Old 10-28-08, 11:19
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
SQLJ is the wrong answer. You can write a stored procedure entirely in Java, which is I guess what you want to do.

There are samples in the DB2 manuals: http://publib.boulder.ibm.com/infoce...d/r0007620.htm
Reply With Quote
  #3 (permalink)  
Old 10-28-08, 11:40
jekyll jekyll is offline
Registered User
 
Join Date: Oct 2008
Posts: 4
Thanks for your reply....I just have one more question. I need to be able to call the java procedure from a normal bog standard sql procedure and wait until there is a return from the java procedure before continuing with the initial procedure. Something like this.....

1) Start initial procedure
2) Call the java procedure from within the initial procedure
3) Wait until the java procedure has returned
4) Complete the initial procedure.

Im sorry to be a pain, however I am very new to DB2 and have not been able to find this exact solution anywhere on the net. I am guessing that the DB2 community is either very quiet, very small, or both :-)
Reply With Quote
  #4 (permalink)  
Old 10-28-08, 11:52
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Sorry, I don't see any question in your second post. A Java stored procedure is invoked in the same manner as an SQL stored procedure. Obviously, you can call one SP from another - that's standard SQL, to which, by the way, DB2 adheres more strictly than Oracle...
Reply With Quote
  #5 (permalink)  
Old 10-28-08, 12:03
jekyll jekyll is offline
Registered User
 
Join Date: Oct 2008
Posts: 4
So you are saying that I can call my java procedure like this.....

"CALL MyJavaProc (params);"

If that is the case it is a lot easier than Oracle.....
Reply With Quote
  #6 (permalink)  
Old 10-28-08, 12:46
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Yes, of course you can do that.

I'm curious: how would this work in Oracle?
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #7 (permalink)  
Old 10-29-08, 02:26
jekyll jekyll is offline
Registered User
 
Join Date: Oct 2008
Posts: 4
In Oracle you have to essentially build a "wrapper procedure" around the class before you can use it.
Reply With Quote
  #8 (permalink)  
Old 10-29-08, 05:47
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Btw, here is an article that describes how to do operating system calls (like file I/O) from SQL: http://www.ibm.com/developerworks/db...303stolze.html
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On