473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DB2CMD in XP - DOS batch file

Folks,

I need to create a batch file that will do the following -

Establish a DB2 instance
Connect to a certain database
Get data using an sql and output it to a file

So, this is what I have done in my test.cmd file

My first command is -

"%ProgramFiles%\ibm\sqllib\bin\db2cmd" /i /w db2 connect to

<db> user <uid> using <pwd>

And this connects me fine.

My second command is -

"%ProgramFiles%\ibm\sqllib\bin\db2cmd" /i /w db2 -tvf

TimSConfqty.sql

This does not execute in batch mode - since it appears that a new
instance of a window was created. If I type in this command at the DOS
prompt created by the 1st command, it works fine. But, it never
executes from the batch test.cmd file. If I type exit at the DOS prompt
- the instance exits and test.cmd continues onto attempting to execute
the 2nd command (which fails, since the first window (instance ?) was
closed.

I think I understand the problem, don't know how to solve it. Well,
maybe I don't understand the problem. Any thoughts ?

Thanks.

Apr 19 '06 #1
7 21569
You've got yhe correct idea but missed one of the details. You need to
place the connect statement in the file with your query. A single
execution of db2cmd is all that's necessary.

Your primary concern should be long term storage of the file containing
the userid and password. If this is a secured database, you will need to
establish appropriate controls over the file(s) containing the password.
Other mechanisms can be used to enable providing a password without
physically storing it on a disk drive but they will add some complexity
to the batch job.
Philip Sherman

rh********@gmail.com wrote:
Folks,

I need to create a batch file that will do the following -

Establish a DB2 instance
Connect to a certain database
Get data using an sql and output it to a file

So, this is what I have done in my test.cmd file

My first command is -

"%ProgramFiles%\ibm\sqllib\bin\db2cmd" /i /w db2 connect to

<db> user <uid> using <pwd>

And this connects me fine.

My second command is -

"%ProgramFiles%\ibm\sqllib\bin\db2cmd" /i /w db2 -tvf

TimSConfqty.sql

This does not execute in batch mode - since it appears that a new
instance of a window was created. If I type in this command at the DOS
prompt created by the 1st command, it works fine. But, it never
executes from the batch test.cmd file. If I type exit at the DOS prompt
- the instance exits and test.cmd continues onto attempting to execute
the 2nd command (which fails, since the first window (instance ?) was
closed.

I think I understand the problem, don't know how to solve it. Well,
maybe I don't understand the problem. Any thoughts ?

Thanks.

Apr 20 '06 #2
Solution offered by Norman W

Create a batch file to initialize a db2 command environment:
initdb2.bat
db2cmd -c -w -i %1.bat

Create a batch file with db2 and operating system commands:
runreport.bat
rem connect to database
db2 connect to sample user xxxx using xxxxx
rem run some sql and output to runreport.out
db2 -vf runreport.sql -z runreport.out

Create a file with sql:
runreport.sql
select count(*) from sysibm.systables

Execute this with:
initdb2 runreport

Apr 20 '06 #3
Solution offered by Norman W

Create a batch file to initialize a db2 command environment:
initdb2.bat
db2cmd -c -w -i %1.bat

Create a batch file with db2 and operating system commands:
runreport.bat
rem connect to database
db2 connect to sample user xxxx using xxxxx
rem run some sql and output to runreport.out
db2 -vf runreport.sql -z runreport.out

Create a file with sql:
runreport.sql
select count(*) from sysibm.systables

Execute this with:
initdb2 runreport

Apr 20 '06 #4
Phil, Thanks. I got this working. What are some of the options about
storing the password ?

Apr 20 '06 #5
This isn't the forum to discuss security issues in. The appropriate
answer to your question depends on your environment, security policies,
government regulations, input from your attorneys and probably a few
other factors.

Phil Sherman

Raj. wrote:
Phil, Thanks. I got this working. What are some of the options about
storing the password ?

Apr 21 '06 #6
Assuming that your using Windows 2000 or above.
Create an user environment variable and store the password in that
variable.

Since it is going to be an user shell environment varaible, other users
except the administrators will not be able to see this setting.

Then use it as follows
db2 connect to sample user xxxx using %password%

'%' s are required. Don't forget to put them around.

Pay back time:
This is something that I learnt from a great great DBI programmer..

regards,

Mehmet Baserdem

Apr 27 '06 #7

Create an user environment variable and store the password in it. (i.e.
mydb2password)

Since it is going to be an user shell environment variable, other users
except the administrators will not be able to see it.

Then use it as follows
db2 connect to sample user xxxx using %mydb2password%

'%' s are required. Don't forget to put them around.

Pay back time:
This is something that I learned from a great great DBI programmer..

regards,

Mehmet Baserdem

Apr 27 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: SkySea | last post by:
Hi! Any help on this would be appreciated... In an HTML document that lists instructions on installing some software, there's a point where a DOS batch file needs to be run in order to copy...
1
by: Rob | last post by:
I'm running a batch file using the Shell function. When I manually launch the batch file, the window remains open, since I use the 'pause' statement. But when I launch the batch file within...
4
by: Bill | last post by:
I need help closing a CMD window when it is executed from Access. 1) The batch file is called from Access. 2) Access closes, 3) the batch runs a copy of the access database (creating a backup)...
3
by: emman_54 | last post by:
Hi every one, I am trying to run a batch file using my asp.net application. I am using the Process class to run the batch file. When I run my web application, In the task manager, i could see...
1
by: steve | last post by:
Hi all, Here's some work in progress that should allow you to run a batch file as a custom action in a VS deployment project. Yup I know you can use js or wsh, but the target may not have...
4
by: ed | last post by:
Hi all, I'm very new to vb (2nd day) and I need to create a small app that will replace my old batch file with a flashy gui. I had some experience with access 2.0 which helps ;) What I would...
7
by: Nananana | last post by:
Hi. I have 2 DB2 statements: connect select How can I create a batch file and redirect the output to a file? I would like something like this:
2
by: da123 | last post by:
I have a clean up proceudre that needs to be scheduled on weekly basis. My company owns a schedular that can kick off MS DOS Batch file for me. If only I can execute the stored procedure from a...
14
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, In my windows applicationm, i need to excute a batch file. this batch file throws some text and questions to the screen, i need to catch the standard Output, check if it's a question, in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.