Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2004
    Posts
    107

    Unanswered: Using DB2 command from a windows shell script

    hi friends,

    i have a list of db2 stored procedures stored as files... i want to write a windows shell script to compile all the stored procedures into the DB2 database...
    i tried to do as follows:
    my script: compile_db2_files.bat
    --------------------------------------------------------------------------
    db2cmd /c /w /i db2 -tf db2compile.db2 -l db2compile.log -r db2report.log
    --------------------------------------------------------------------------
    and the db2compile.db2 file contains
    --------------------------------------------------------------------------
    connect to sample;
    -td@ -f all_data_types.sql;
    -td@ -f all_data_types11.sql;
    --------------------------------------------------------------------------

    executed the script as follows:
    --------------------------------------------------------------------------
    db2cmd -c -w -i compile_db2_files.bat
    --------------------------------------------------------------------------

    the output in the command prompt is:
    --------------------------------------------------------------------------

    Database Connection Information

    Database server = DB2/NT 8.1.0
    SQL authorization ID = JAYAKUMA...
    Local database alias = SAMPLE


    DB21034E The command was processed as an SQL statement because it was not a
    valid Command Line Processor command. During SQL processing it returned:
    SQL0104N An unexpected token "-" was found following "BEGIN-OF-STATEMENT".
    Expected tokens may include: "SELECT". SQLSTATE=42601
    --------------------------------------------------------------------------

    plz can anyone tell me where i'm going wrong???

    Jake

  2. #2
    Join Date
    Jan 2003
    Posts
    1,605
    Hi,

    "db2 -tf ..." -t means the sql file has ";" character delimiter. Try to remove this from command so: "db2 -f ...".

    Hope this helps,
    Grofaty

  3. #3
    Join Date
    Feb 2004
    Posts
    107
    thanks for your reply. i tried what u said.
    but if u see the db2compile.db2 file, i terminated every command with ";". so after i removed "t" it says "sample;" database doesn't exist. of course, it is right, since ";" considered as a valid character. then i removed the ";" but this time too it says the same error. good u please tell me how to specify a command to compile a stored procedure file within the db2 command file, ie in db2compile.db2 file in my case...

    Appreciate your effort.
    Jake

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Quote Originally Posted by Jake K
    and the db2compile.db2 file contains
    Code:
    connect to sample;
    -td@ -f all_data_types.sql;
    -td@ -f all_data_types11.sql;
    A db2 script (db2compile.db2 in your case) can only contain SQL statements and CLP commands; "-td@ -f all_data_types.sql" is neither.

    You'll have to execute the "all_data_types*" scripts separately:
    Code:
    db2cmd db2 -td@ -f all_data_types.sql
    db2cmd db2 -td@ -f all_data_types11.sql
    Note that you'll need to include "connect" command in each of them in that case.

  5. #5
    Join Date
    Feb 2004
    Posts
    107
    thanks for the clarification....

    since i have a large number of files, it is difficult for me to add 'conect to sample' statement to every procedure.
    so can you tell me anyother alternative
    Appreciate your help.
    Jake

  6. #6
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Create a batch (say, "allproc.bat") file containing
    Code:
    db2 connect to ...
    db2 -td@ -f all_data_types.sql
    db2 -td@ -f all_data_types11.sql
    ...
    db2 connect reset
    and run
    Code:
    db2cmd /c allproc.bat

  7. #7
    Join Date
    Feb 2004
    Posts
    107
    hurray! it works...
    thanks buddy

    Jake

  8. #8
    Join Date
    May 2011
    Posts
    15

    thanks

    hi,

    Thanks........... for the bat file
    I also want this

Posting Permissions

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