Hello, I have a very simple script (or would you call it a batch
file?) with the following content:
connect to mydb2;
DROP TABLE staff_employee_address;
DROP TABLE staff_employee_address_telephone;
DROP TABLE staff_employee;
DROP TABLE staff;
commit;
terminate;
I'm trying to run this script using a combination of db2cmd / db2 clp
launched from a Java program. I'm using Windows Vista, so that's why I
am using db2cmd (that sets up the environment for the db2 clp if I
understood things correctly).
The actual java code is:
String cmd = "db2cmd -c -i -w db2 +c -tvf path/to/script.sql -z
outfile.txt"
Process p = Runtime.getRuntime().exec(cmd);
System.out.println("The exit code was: " p.waitFor());
Unfortunately, waitFor() never returns so my Java program grinds to a
halt. If I look in outfile.txt I see:
connect to mydb2
Database Connection Information
Database server = DB2/NT 9.5.1
SQL authorization ID = LOKALADM
Local database alias = MYDB2
DROP TABLE staff_employee_address
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL0204N "LOKALADM.STAFF_EMPLOYEE_ADDRESS" is an undefined name.
SQLSTATE=42704
DROP TABLE staff_employee_address_telephone
DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
as you can see it has stopped writing output midway. This particular
run was done at a time where the tables that are supposed to be
dropped doesn't actually exist.
Here I'm running it when the tables do exist, waitFor() still doesn't
return and the outfile lacks information about the commit and
terminate commands being run (the tables are dropped, however):
connect to mydb2
Database Connection Information
Database server = DB2/NT 9.5.1
SQL authorization ID = LOKALADM
Local database alias = MYDB2
DROP TABLE staff_employee_address
DB20000I The SQL command completed successfully.
DROP TABLE staff_employee_address_telephone
DB20000I The SQL command completed successfully.
DROP TABLE staff_employee
DB20000I The SQL command completed successfully.
DROP TABLE staff
DB20000I The SQL command completed successfully.
So then I tried issuing the four drop table statements from inside the
control center and it only stalls if my java program is currently
running and stalled.
Any ideas on how to solve it? My boss is getting a bit impatient I
think, heh, because this was supposed to be a straightforward task. I
was actually using db2batch at first but ran into problems as soon as
I used this script and tried to drop non-existant tables so I switched
to db2cmd/db2 clp instead but still no go, I'm afraid. :-(
The commit; terminate; part was added just now to see if that solved
things but, unfornately, it didn't.
- Eric Lilja