Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2013
    Posts
    13

    Unanswered: Execute a batch file from stored Procedure

    Hi All,

    I would like to know is it possible to execute a batch file from stored procedure?
    The batch file will be located at db2 server.
    I would like to execute the stored procedure through web application.
    If yes, what is the right way to do it?



    Thanks.
    Last edited by pangjiu; 05-13-13 at 01:19.

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Calling any code outside of the database from within a trigger is generally a bad idea. It leads to all kinds of potential performance, validation, and management problems.

    Use the trigger to stage data, and possibly to queue or launch a job (via a separate execution thread). I would not transfer execution control outside of the database unless I had no other viable choice.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Apr 2013
    Posts
    13
    Thanks for the reply.
    Actually i need to get the result for "List DB Directory". However, it only can be executed from CLP. That's is the reason i was thinking to put the batch file inside stored procedure, then i could just execute the stored procedure from my c# web application.
    I have google for many days but i cant find any other solution.

    I'm very new to db2.

    Thanks.

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Is your DB2 instance running on Windows, Linix, AIX, AS/400, zOS, or something different? Since the term "batch file" is specific to Microsoft Windows, that seems like a somewhat safe bet.

    If I had a need to do this, I'd create an external job and schedule it. That job would acquire the information that you need, and put it into a table. This would decouple the file system task from the database, but still keep the information readily available. If DB2 can launch a job from your scheduling package that would be acceptable, but a short polling interval (say 60-300 seconds) is probably a better solution.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  5. #5
    Join Date
    Apr 2013
    Posts
    13
    Thanks for reply PatP. Really appreciate on your reply.
    As i really too new to db2, i think i need to learn on how to create an external job and schedule it in db2. Do you have any quick learning guideline?
    Thanks

  6. #6
    Join Date
    Apr 2013
    Posts
    13
    May i know how to create a stored procedure which can invoke 'list db directory'?
    Thanks

  7. #7
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    db2 commands can not be executed from an sp
    you can use admin_cmd to call some utilities but list db dir is not part of this list
    in developerswork there is a sample how to call an o/s command from within an sp..
    have a look over there and search for os_cmd
    Best Regards, Guy Przytula
    Database Software Consultant
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

  8. #8
    Join Date
    Mar 2006
    Location
    Bogota, Colombia
    Posts
    21

    External Stored Procedure

    You can create a stored procedure in Java or in C and call the batch directly from that code.

    For example in Java, you create the external SP, and call the batch via Runtime.exec.
    AngocA

  9. #9
    Join Date
    Apr 2013
    Posts
    13
    Thank for reply Angoca. I know it could be done in Java but how about c#? What is the right syntax to call the batch file from c# code?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •