"Kai-Uwe Klavei" <kl****@gmx.de> 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="Creates and populates database tables.">
<sql
classpath="${class.path}"
driver="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@//localhost:1521/orcl"
userid="technical_library"
password="na"
rdbms="oracle"
version="10.1.0.2.0"
onerror="continue">
<transaction src="${base.dir}/purge_technical_library.sql"/>
<transaction src="${base.dir}/create_technical_library.sql"/>
<transaction src="${base.dir}/populate_technical_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_Stored_Proc" description="Prepare stored procedure">
<sql classpath="C:/Program Files/SQLLIB/java/db2java.zip"
driver="COM.ibm.db2.jdbc.app.DB2Driver" url="jdbc:db2:sample" userid="rhino"
password="rhino" onerror="continue" 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_Proc:
Adding reference: eclipse.progress.monitor
[sql] connecting to jdbc:db2:sample
[sql] Loading COM.ibm.db2.jdbc.app.DB2Driver using AntClassLoader with
classpath C:\Program Files\SQLLIB\java\db2java.zip
Finding class COM.ibm.db2.jdbc.app.DB2Driver
Loaded from C:\Program Files\SQLLIB\java\db2java.zip
COM/ibm/db2/jdbc/app/DB2Driver.class
Class java.lang.Object loaded from parent loader (parentFirst)
Class java.sql.Driver loaded from parent loader (parentFirst)
Class COM.ibm.db2.jdbc.app.DB2Driver loaded from ant loader (parentFirst)
Class java.util.Hashtable loaded from parent loader (parentFirst)
Class java.util.Properties loaded from parent loader (parentFirst)
Class java.sql.Connection loaded from parent loader (parentFirst)
Class java.lang.Throwable loaded from parent loader (parentFirst)
Class java.sql.SQLException loaded from parent loader (parentFirst)
Class java.lang.UnsatisfiedLinkError loaded from parent loader (parentFirst)
Class java.security.PrivilegedAction loaded from parent loader (parentFirst)
Class java.lang.String loaded from parent loader (parentFirst)
Finding class COM.ibm.db2.jdbc.app.DB2Driver$1
Loaded from C:\Program Files\SQLLIB\java\db2java.zip
COM/ibm/db2/jdbc/app/DB2Driver$1.class
Class COM.ibm.db2.jdbc.app.DB2Driver$1 loaded from ant loader (parentFirst)
Class java.security.AccessController loaded from parent loader (parentFirst)
Class java.lang.System loaded from parent loader (parentFirst)
Finding class COM.ibm.db2.jdbc.app.DB2Driver$3
Loaded from C:\Program Files\SQLLIB\java\db2java.zip
COM/ibm/db2/jdbc/app/DB2Driver$3.class
Class COM.ibm.db2.jdbc.app.DB2Driver$3 loaded from ant loader (parentFirst)
Finding class COM.ibm.db2.mri.DB2Messages
Loaded from C:\Program Files\SQLLIB\java\db2java.zip
COM/ibm/db2/mri/DB2Messages.class
Class COM.ibm.db2.mri.DB2Messages loaded from ant loader (parentFirst)
Class java.util.ResourceBundle loaded from parent loader (parentFirst)
Finding class COM.ibm.db2.mri.DB2ErrorMessages
Loaded from C:\Program Files\SQLLIB\java\db2java.zip
COM/ibm/db2/mri/DB2ErrorMessages.class
Class java.util.ListResourceBundle loaded from parent loader (parentFirst)
Class COM.ibm.db2.mri.DB2ErrorMessages loaded from ant loader (parentFirst)
Finding class COM.ibm.db2.mri.DB2ErrorMessages_en
Loaded from C:\Program Files\SQLLIB\java\db2java.zip
COM/ibm/db2/mri/DB2ErrorMessages_en.class
Class COM.ibm.db2.mri.DB2ErrorMessages_en loaded from ant loader
(parentFirst)
Finding class COM.ibm.db2.mri.DB2ErrorMessages_en_CA
Couldn't load ResourceStream for
COM/ibm/db2/mri/DB2ErrorMessages_en_CA.properties
Class java.lang.StringBuffer loaded from parent loader (parentFirst)
Class java.sql.DriverManager loaded from parent loader (parentFirst)
[sql] BUILD FAILED: D:\eclipse\workspace\Ron Devine\xml\build.xml:160:
java.sql.SQLException: java.lang.UnsatisfiedLinkError: Native Library
C:\Program Files\SQLLIB\bin\db2jdbc.dll already loaded in another
classloader
I googled but couldn't find out much of any use about this
java.lang.UnsatisfiedLinkError, 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