473,657 Members | 2,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ant and DB2

I am using DB2 V7.2.7 on Windows XP and I would like to write Ant 1.6.1
scripts that do some of my program preparation. For the benefit of those not
familiar with Ant, it is an open source equivalent to 'make'.

Although there are no specific DB2 tasks in Ant, there is an exec task that
is functionally equivalent to a command line. For instance, to run a 'dir'
command in an Ant exec task, you would write:
<exec executable="cmd .exe" os="Windows XP" output="dir.txt ">

<arg value="/c dir"/>

</exec>

This executes the Windows XP cmd.exe program, executes the 'dir' command,
and writes the output to a file called 'dir.txt'.

With that background out of the way, can anyone tell me how to execute a db2
command that needs a db2 connection?

I can execute a db2 command that *doesn't* need a connection successfully
this way:

<exec executable="cmd .exe" os="Windows XP">

<arg value="/c db2cmd db2 get dbm cfg"/>

</exec>

However, I haven't figured out how to execute a command that *does* need a
connection. I'd like to be able to get a connection and then issue a CREATE
PROCEDURE or a COMMENT ON that affects objects in the database to which I'm
connected.

I'd appreciate any guidance that anyone could give.

I've googled but haven't seen anything concrete on how Ant could be used to
do what I'm trying to do.

--
Rhino
---
rhino1 AT sympatico DOT ca
"If you're getting something for nothing, you're not using your own credit
card."
Nov 12 '05 #1
7 9296
Rhino wrote:
I am using DB2 V7.2.7 on Windows XP and I would like to write Ant 1.6.1
scripts that do some of my program preparation.[...]

However, I haven't figured out how to execute a command that *does* need a
connection. I'd like to be able to get a connection and then issue a CREATE
PROCEDURE or a COMMENT ON that affects objects in the database to which I'm
connected.


You can use the Ant Core Task "sql" - take a look at the provided
examples in the documentation.

Here is an example target I used before - as you can see this one is for
an Oracle database:

<target name="dbinit" depends=""
description="Cr eates and populates database tables.">
<sql
classpath="${cl ass.path}"
driver="oracle. jdbc.OracleDriv er"
url="jdbc:oracl e:thin:@//localhost:1521/orcl"
userid="technic al_library"
password="na"
rdbms="oracle"
version="10.1.0 .2.0"
onerror="contin ue">
<transaction src="${base.dir }/purge_technical _library.sql"/>
<transaction src="${base.dir }/create_technica l_library.sql"/>
<transaction src="${base.dir }/populate_techni cal_library.sql "/>
</sql>
</target>

Kai-Uwe

Nov 12 '05 #2
On 2004-04-14, Rhino scribbled:

[Snip]
I can execute a db2 command that *doesn't* need a connection
successfully this way:

<exec executable="cmd .exe" os="Windows XP">

<arg value="/c db2cmd db2 get dbm cfg"/>

</exec>

However, I haven't figured out how to execute a command that does
need a connection. I'd like to be able to get a connection and then
issue a CREATE PROCEDURE or a COMMENT ON that affects objects in the
database to which I'm connected.

[Snip]

If Ant has some mechanism where it can interface to a database (through
JDBC I guess since it's a Java app), you could use that - though you
wouldn't be able to run DB2 utilities like RUNSTATS, IMPORT or LOAD
since they're not SQL commands.

I've come across a similar sitation when writing bash scripts for DB2
with Cygwin under Windows (which needed to run such utilities). The
problem is the peculiar "db2cmd" application. Under Linux/UNIX this
doesn't exist, and you'd be able to do what you're trying to.

I'm not 100% sure what's going on with it, but the following theory
seems to fit: The "db2cmd" application holds some sort of session or
connection handle open which the "db2" application uses. Therefore all
SQL commands which require an open connection must happen within a
series of "db2" commands running within a *continuous* "db2cmd" session.

I got around this in my bash scripts by generating a load of commands,
dumping them to a temporary text file, then running something like

db2cmd -iw -c db2 -tv -f some_temp_file. sql

To ensure that all the commands are run within a single "db2cmd"
session. I'm guessing you could resort to something similar with
Ant. Either get your script to write out the SQL to a temporary file
and remove it after it's done, or have an SQL file which accompanies
the Ant script, and use something like:

<exec executable="db2 cmd.exe" os="Windows XP">
<arg value="-i"/>
<arg value="-w"/>
<arg value="-c db2 -tvf some_sql.sql"/>
</exec>

BTW, the -i and -w switches just ensure that the db2cmd session runs
under the same console and inherit the same stdin/stdout handles as Ant
is using - but you may not need them (under bash they were useful as I
could then use redirects for logging purposes, or pipe SQL commands
through stdin instead of using an input file).

HTH, Dave.

--
Dave
Remove "_nospam" for valid e-mail address

"Never underestimate the bandwidth of a station wagon full of CDs doing
a ton down the highway" -- Anon.
Nov 12 '05 #3

"Kai-Uwe Klavei" <kl****@gmx.d e> wrote in message
news:c5******** *****@news.t-online.com...
Rhino wrote:
I am using DB2 V7.2.7 on Windows XP and I would like to write Ant 1.6.1
scripts that do some of my program preparation.[...]

However, I haven't figured out how to execute a command that *does* need a connection. I'd like to be able to get a connection and then issue a CREATE PROCEDURE or a COMMENT ON that affects objects in the database to which I'm connected.


You can use the Ant Core Task "sql" - take a look at the provided
examples in the documentation.

Here is an example target I used before - as you can see this one is for
an Oracle database:

<target name="dbinit" depends=""
description="Cr eates and populates database tables.">
<sql
classpath="${cl ass.path}"
driver="oracle. jdbc.OracleDriv er"
url="jdbc:oracl e:thin:@//localhost:1521/orcl"
userid="technic al_library"
password="na"
rdbms="oracle"
version="10.1.0 .2.0"
onerror="contin ue">
<transaction src="${base.dir }/purge_technical _library.sql"/>
<transaction src="${base.dir }/create_technica l_library.sql"/>
<transaction src="${base.dir }/populate_techni cal_library.sql "/>
</sql>
</target>

For the sake of those following this thread, now or in the future, I was
not able to make this work using the following code:

<target name="Prep_Stor ed_Proc" description="Pr epare stored procedure">

<sql classpath="C:/Program Files/SQLLIB/java/db2java.zip"

driver="COM.ibm .db2.jdbc.app.D B2Driver" url="jdbc:db2:s ample" userid="rhino"

password="rhino " onerror="contin ue" caching="yes" print="yes"

output="sql.out ">

comment on specific procedure income_proc is 'Rhino';

get dbm cfg;

</sql>

</target>

The first time I ran it, it *almost* worked - only the first of the two
commands executed - but on the second and subsequent attempts I got an error
message. Since I had the -debug and -verbose switches on, here is the entire
output stream:

Prep_Stored_Pro c:

Adding reference: eclipse.progres s.monitor

[sql] connecting to jdbc:db2:sample

[sql] Loading COM.ibm.db2.jdb c.app.DB2Driver using AntClassLoader with
classpath C:\Program Files\SQLLIB\ja va\db2java.zip

Finding class COM.ibm.db2.jdb c.app.DB2Driver

Loaded from C:\Program Files\SQLLIB\ja va\db2java.zip
COM/ibm/db2/jdbc/app/DB2Driver.class

Class java.lang.Objec t loaded from parent loader (parentFirst)

Class java.sql.Driver loaded from parent loader (parentFirst)

Class COM.ibm.db2.jdb c.app.DB2Driver loaded from ant loader (parentFirst)

Class java.util.Hasht able loaded from parent loader (parentFirst)

Class java.util.Prope rties loaded from parent loader (parentFirst)

Class java.sql.Connec tion loaded from parent loader (parentFirst)

Class java.lang.Throw able loaded from parent loader (parentFirst)

Class java.sql.SQLExc eption loaded from parent loader (parentFirst)

Class java.lang.Unsat isfiedLinkError loaded from parent loader (parentFirst)

Class java.security.P rivilegedAction loaded from parent loader (parentFirst)

Class java.lang.Strin g loaded from parent loader (parentFirst)

Finding class COM.ibm.db2.jdb c.app.DB2Driver $1

Loaded from C:\Program Files\SQLLIB\ja va\db2java.zip
COM/ibm/db2/jdbc/app/DB2Driver$1.cla ss

Class COM.ibm.db2.jdb c.app.DB2Driver $1 loaded from ant loader (parentFirst)

Class java.security.A ccessController loaded from parent loader (parentFirst)

Class java.lang.Syste m loaded from parent loader (parentFirst)

Finding class COM.ibm.db2.jdb c.app.DB2Driver $3

Loaded from C:\Program Files\SQLLIB\ja va\db2java.zip
COM/ibm/db2/jdbc/app/DB2Driver$3.cla ss

Class COM.ibm.db2.jdb c.app.DB2Driver $3 loaded from ant loader (parentFirst)

Finding class COM.ibm.db2.mri .DB2Messages

Loaded from C:\Program Files\SQLLIB\ja va\db2java.zip
COM/ibm/db2/mri/DB2Messages.cla ss

Class COM.ibm.db2.mri .DB2Messages loaded from ant loader (parentFirst)

Class java.util.Resou rceBundle loaded from parent loader (parentFirst)

Finding class COM.ibm.db2.mri .DB2ErrorMessag es

Loaded from C:\Program Files\SQLLIB\ja va\db2java.zip
COM/ibm/db2/mri/DB2ErrorMessage s.class

Class java.util.ListR esourceBundle loaded from parent loader (parentFirst)

Class COM.ibm.db2.mri .DB2ErrorMessag es loaded from ant loader (parentFirst)

Finding class COM.ibm.db2.mri .DB2ErrorMessag es_en

Loaded from C:\Program Files\SQLLIB\ja va\db2java.zip
COM/ibm/db2/mri/DB2ErrorMessage s_en.class

Class COM.ibm.db2.mri .DB2ErrorMessag es_en loaded from ant loader
(parentFirst)

Finding class COM.ibm.db2.mri .DB2ErrorMessag es_en_CA

Couldn't load ResourceStream for
COM/ibm/db2/mri/DB2ErrorMessage s_en_CA.propert ies

Class java.lang.Strin gBuffer loaded from parent loader (parentFirst)

Class java.sql.Driver Manager loaded from parent loader (parentFirst)

[sql] BUILD FAILED: D:\eclipse\work space\Ron Devine\xml\buil d.xml:160:
java.sql.SQLExc eption: java.lang.Unsat isfiedLinkError : Native Library
C:\Program Files\SQLLIB\bi n\db2jdbc.dll already loaded in another
classloader

I googled but couldn't find out much of any use about this
java.lang.Unsat isfiedLinkError , particularly why the db2jdbc.dll is "already
be loaded in another classloader". The only remedy to the problem I could
find was "kill all the processes". Since no further details were provided, I
simply rebooted rather than trying to guess which of the processes on this
machine needed to be killed.

For what it's worth, I set caching=yes before attempting the Ant task again
(after I rebooted) but the same problem occurred.

I still have hopes of making this approach work someday - if someone can
tell me how to prevent this problem from recurring - but, for now I have
another solution that works. See my comments on the other reply I got to my
original post for the details.

Rhino
Nov 12 '05 #4

"Dave Hughes" <da*********@wa veform.plus.com > wrote in message
news:xn******** ********@usenet .plus.net...
On 2004-04-14, Rhino scribbled:

[Snip]
I can execute a db2 command that *doesn't* need a connection
successfully this way:

<exec executable="cmd .exe" os="Windows XP">

<arg value="/c db2cmd db2 get dbm cfg"/>

</exec>

However, I haven't figured out how to execute a command that does
need a connection. I'd like to be able to get a connection and then
issue a CREATE PROCEDURE or a COMMENT ON that affects objects in the
database to which I'm connected.

[Snip]

If Ant has some mechanism where it can interface to a database (through
JDBC I guess since it's a Java app), you could use that - though you
wouldn't be able to run DB2 utilities like RUNSTATS, IMPORT or LOAD
since they're not SQL commands.

I've come across a similar sitation when writing bash scripts for DB2
with Cygwin under Windows (which needed to run such utilities). The
problem is the peculiar "db2cmd" application. Under Linux/UNIX this
doesn't exist, and you'd be able to do what you're trying to.

I'm not 100% sure what's going on with it, but the following theory
seems to fit: The "db2cmd" application holds some sort of session or
connection handle open which the "db2" application uses. Therefore all
SQL commands which require an open connection must happen within a
series of "db2" commands running within a *continuous* "db2cmd" session.

I got around this in my bash scripts by generating a load of commands,
dumping them to a temporary text file, then running something like

db2cmd -iw -c db2 -tv -f some_temp_file. sql

To ensure that all the commands are run within a single "db2cmd"
session. I'm guessing you could resort to something similar with
Ant. Either get your script to write out the SQL to a temporary file
and remove it after it's done, or have an SQL file which accompanies
the Ant script, and use something like:

<exec executable="db2 cmd.exe" os="Windows XP">
<arg value="-i"/>
<arg value="-w"/>
<arg value="-c db2 -tvf some_sql.sql"/>
</exec>

BTW, the -i and -w switches just ensure that the db2cmd session runs
under the same console and inherit the same stdin/stdout handles as Ant
is using - but you may not need them (under bash they were useful as I
could then use redirects for logging purposes, or pipe SQL commands
through stdin instead of using an input file).

Your suggested solution didn't quite work but helped me get to this, which
does work:

<exec executable="cmd .exe" os="Windows XP">

<arg value="/c db2cmd db2 -tvf db2_001.in -z db2_001.out"/>

</exec>
where db2_001.in, the input file, contained:

connect to sample;

comment on table employee is 'ZZZ';

quit;

For anyone following this thread now or in the future, I also tried using
the 'output' parameter in the exec tag rather than using the -z flag in the
arg tag but it didn't work; the output file was empty afterwards. The -o
flag would have worked instead of the -z flag but I prefer to see both the
command and its result in the same file so I use -z.

Each time this task is run, the output just keeps getting appended to the
output file, db2_001.out, so it would be a good idea to add a 'delete' task
that deletes db2_001.out each time before you run the <exec> task. That
would look like this:

<delete file="db2_001.o ut"/>

The entire task, with the delete step, would look like this:

<target name="DB2_Stuff " description="Do DB2 stuff.">

<delete file="db2_001.o ut"/>

<exec executable="cmd .exe" os="Windows XP">

<arg value="/c db2cmd db2 -tvf db2_001.in -z db2_001.out"/>

</exec>

<exec executable="cmd .exe" os="Windows XP">

<arg value="/c db2cmd db2 get dbm cfg"/>

</exec>

</target>

The second 'exec' step in this example shows how to execute a db2 command
that *doesn't* need a database connection without having to resort to input
files and db2 -tvf.

For what it's worth, all of these examples were executed on Windows XP using
Ant 1.6.1, the latest version. No guarantees that these same examples will
work the same on other operating systems or older versions of Ant!

I hope this helps someone down the road....

Rhino
Nov 12 '05 #5
Rhino wrote:
For the sake of those following this thread, now or in the future, I
was not able to make this work using the following code:

<target name="Prep_Stor ed_Proc"
description="Pr epare stored procedure">
<sql
classpath="C:/Program Files/SQLLIB/java/db2java.zip"
driver="COM.ibm .db2.jdbc.app.D B2Driver"
url="jdbc:db2:s ample" userid="rhino" password="rhino "
onerror="contin ue" caching="yes" print="yes"
output="sql.out ">
comment on specific procedure income_proc is 'Rhino';
get dbm cfg;
</sql>
</target>

The first time I ran it, it *almost* worked - only the first of the
two commands executed - but on the second and subsequent attempts I
got an error message. Since I had the -debug and -verbose switches
on, here is the entire output stream:
[...]
[sql] BUILD FAILED: D:\eclipse\work space\Ron Devine\xml\buil d.xml:160:
java.sql.SQLExc eption: java.lang.Unsat isfiedLinkError : Native Library
C:\Program Files\SQLLIB\bi n\db2jdbc.dll already loaded in another
classloader


In fact COM.ibm.db2.jdb c.app.DB2Driver is a type 2 driver that relies on
a native library.

The error seems to be a bug - I found this:
http://jce.iaik.tugraz.at/products/1...index.php#Q1_4

The second command "get dbm cfg" is a CLP command, not an SQL command,
it cannot be executed via JDBC.

Execute it via the system command db2cmd in an Ant exec task as you did
before.

Kai-Uwe
Nov 12 '05 #6

"PM (pm3iinc-nospam) CGO" <PM (pm3iinc-nospam)@cgocabl e.ca> wrote in message
news:qx******** *********@charl ie.risq.qc.ca.. .
You may scan db2dd just in case.
http://www-106.ibm.com/search/search...searchScope=dW
PM

Great suggestion!

I've already found a couple of articles that have enhanced my understanding
of Ant.

Rhino
Nov 12 '05 #8

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

Similar topics

3
11205
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL) on the server because of that. Our site will have an SSL certificate next week, so I would like to use AIM instead of SIM, however, I don't know how to send data via POST over https and recieve data from the Authorize.net server over an https...
2
5801
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues to execute the code until the browser send his reply to the header instruction. So an exit(); after each redirection won't hurt at all
3
22994
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which field is completed.
0
8460
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. 354 roberto@ausone:Build/php-4.3.2> ldd /opt/php4/bin/php libsablot.so.0 => /usr/local/lib/libsablot.so.0 libstdc++.so.5 => /usr/local/lib/libstdc++.so.5 libm.so.1 => /usr/lib/libm.so.1
1
8564
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the column below. The viewer can select states from the drop down lists above the other two columns as well. If the viewer selects only one, only one column fills. If the viewer selects two states, two columns fill. Etc. I could, if appropriate, have...
4
18252
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the user comes back to a page where he had a submitted POST data the browser keeps telling that the data has expired and asks if repost. How to avoid that? I tried registering all POST and GET vars as SESSION vars but
1
6810
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url http://www.mis.gla.ac.uk/biquery/training/ but each of the courses held have maximum of 8 people that could be
2
31391
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value to :parameter I dont like the idea of making the SQL statement on the fly without binding parameters as I dont want a highly polluted SQL cache.
3
23564
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the results of the picture half the size. The PHP I have installed support 1.62 or higher. And all I would like to do is take and image and make it fit a 3x3. Any suggestions to where I should read or look would be appreciated.
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8730
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1950
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1607
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.