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 > Using DB2 command from a windows shell script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-07-04, 07:38
Jake K Jake K is offline
Registered User
 
Join Date: Feb 2004
Posts: 107
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
Reply With Quote
  #2 (permalink)  
Old 07-07-04, 08:38
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,

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

Hope this helps,
Grofaty
Reply With Quote
  #3 (permalink)  
Old 07-07-04, 08:46
Jake K Jake K is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 07-07-04, 09:48
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
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.
Reply With Quote
  #5 (permalink)  
Old 07-07-04, 11:22
Jake K Jake K is offline
Registered User
 
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
Reply With Quote
  #6 (permalink)  
Old 07-07-04, 13:44
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
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
Reply With Quote
  #7 (permalink)  
Old 07-08-04, 01:42
Jake K Jake K is offline
Registered User
 
Join Date: Feb 2004
Posts: 107
hurray! it works...
thanks buddy

Jake
Reply With Quote
  #8 (permalink)  
Old 05-26-11, 03:20
super_mpk super_mpk is offline
Registered User
 
Join Date: May 2011
Posts: 15
thanks

hi,

Thanks........... for the bat file
I also want this
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