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 > Executing DB2 Commands as a Batch File

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-21-09, 08:40
Neharao Neharao is offline
Registered User
 
Join Date: Dec 2007
Posts: 49
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

dos scripits for db2

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

Thanks
Neha
Reply With Quote
  #2 (permalink)  
Old 04-21-09, 09:10
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
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
Reply With Quote
  #3 (permalink)  
Old 05-03-09, 14:11
Neharao Neharao is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 05-03-09, 17:31
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
try executing your bat file from DB2 CLP. The output file will be created in the current dir
Reply With Quote
  #5 (permalink)  
Old 05-04-09, 08:20
Neharao Neharao is offline
Registered User
 
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

dos scripits for db2
Reply With Quote
  #6 (permalink)  
Old 05-04-09, 08:26
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
The on the filename after the -z specify a path:

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

Andy
Reply With Quote
  #7 (permalink)  
Old 05-05-09, 01:22
Neharao Neharao is offline
Registered User
 
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
Reply With Quote
  #8 (permalink)  
Old 05-05-09, 02:04
tukyunaaya tukyunaaya is offline
Registered User
 
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!
Reply With Quote
  #9 (permalink)  
Old 05-05-09, 08:35
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
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
Reply With Quote
  #10 (permalink)  
Old 05-06-09, 10:02
MarkhamDBA MarkhamDBA is offline
Registered User
 
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
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 v9.5 ESE on AIX v6.1/ v9./10 on z/OS
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