Results 1 to 10 of 10
  1. #1
    Join Date
    Dec 2007
    Posts
    49

    Unanswered: Executing DB2 Commands as a Batch File

    Hi All

    I am trying to run some set of DB2 commands as a Batch file on windows

    I wrote the below commands in a batch file, saved it as a .bat file and expecting it to run with a double click and produce the output in sqllres.out

    db2 connect to SAMPLE
    db2 select * from SAMPLE > sqlres.out
    db2 commit
    db2 connect reset

    I did refer to the below link

    http://www.dbforums.com/db2/1615385-...ipits-db2.html

    But couldnt arrive at the solution. Any solutions in this regard will be helpful.

    Thanks
    Neha

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    I would make a script file that has the DB2 commands you want (Myscript.sql):

    connect to SAMPLE
    select * from SAMPLE
    commit
    connect reset

    Then your batch file would contain just one line:

    db2 -z sqlres.out -tvsf Myscript.sql

    Andy

  3. #3
    Join Date
    Dec 2007
    Posts
    49
    Sorry for very late reply ,

    But the solution didnt work , More over I couldnt find where does this file sqlres.out resides , Which was mentioned in the command

    db2 -z sqlres.out -tvsf Myscript.sql

    When i saved the above in a file and named it as test.bat , And when i executed it with a double click , It just flashed away , without being stable on the windows screen till i close. I was expecting it to show the SQL status of each message executed from the script file.

    Can u please suggest me something

  4. #4
    Join Date
    Aug 2008
    Location
    Toronto, Canada
    Posts
    2,367
    try executing your bat file from DB2 CLP. The output file will be created in the current dir

  5. #5
    Join Date
    Dec 2007
    Posts
    49
    I would like to run the bat file with just a double click , Dont want to run it from Db2clp , by issuing another command

    i did refer to this link as well

    http://www.dbforums.com/db2/1615385-...ipits-db2.html

  6. #6
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    The on the filename after the -z specify a path:

    db2 -z C:\Mypath\sqlres.out -tvsf Myscript.sql

    Andy

  7. #7
    Join Date
    Dec 2007
    Posts
    49
    Hi
    Even that didnt work

    I have written the below lines in myscript.sql

    db2 connect to SAMPLE
    db2 select * from SAMPLE
    db2 commit
    db2 connect reset


    And writen the below line in a file with the name test.bat

    db2 -z C:\sqlres.out -tvsf C:\myscript.sql

    I even tried with

    db2 -z C:\sqlres.out -tvsf myscript.sql ( As u specified in the mail )

    but both of them didnt work . Please let me know if i need to set any path or Db2 Variables.

    Thanks

  8. #8
    Join Date
    Feb 2009
    Posts
    14
    hi..make a bat file of your commands..

    save it as command.bat in the folder location

    C:\Documents and Settings\your username

    now..in run type "db2cmd" without quotes and press enter.
    you will find the cmd window opening there,and the prompt will be
    C:\Documents and Settings\your username>
    now here press C ( the first character of you bat file) and hit tab to c the files name starting with C.now it will come command.bat after pressing tab,so hit enter and you are done..

    easy way is..write command.bat in C:\Documents and Settings\your username> if you have only few bat files..

    i hope this wil help you..



    sample bat file

    db2 -x connect to xxxxxx user xxxx USING xxx
    db2 -x set current sqlid='aaaaa'
    db2 -x set current schema='bbbbb'
    db2 -x set current path=bbbbb,current path
    db2 -x select current path from sysibm.sysdummy1
    db2 -td@
    Please don't spam!

  9. #9
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Quote Originally Posted by Neharao
    Hi
    Even that didnt work

    I have written the below lines in myscript.sql

    db2 connect to SAMPLE
    db2 select * from SAMPLE
    db2 commit
    db2 connect reset


    And writen the below line in a file with the name test.bat

    db2 -z C:\sqlres.out -tvsf C:\myscript.sql

    I even tried with

    db2 -z C:\sqlres.out -tvsf myscript.sql ( As u specified in the mail )

    but both of them didnt work . Please let me know if i need to set any path or Db2 Variables.

    Thanks
    Your script file should look like this:

    connect to SAMPLE
    select * from SAMPLE
    commit
    connect reset

    Andy

  10. #10
    Join Date
    Dec 2008
    Location
    Toronto, Canada
    Posts
    399
    if you run it this way all commands should end with ;
    On AIX no 'db2' needed:

    connect to SAMPLE;
    select * from SAMPLE;
    commit;
    connect reset;
    DB2 9.5/9.7 on Unix/AIX 6.1/Linux

Posting Permissions

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