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.
Hi All,
I wanted to know if I could use the export or import utility from inside a java program on my db2 server.
i.e programatically generate the export data and message files to a particular location.
Yes it can be done. If you have DB2 V8.2 FP 9 or greater, you can use the ADMIN_CMD SP to do the export, but his can only be run on the server locally. Import, currently, cannot be done this way but will be soon.
Both can be done another way that works both remotely and locally by using the Runtime class in java. There are example at:
it was great.
I tried the solutions you provided.
My DB2 is : 8.2.4; so I think it is fine.
Well, I am getting this error:
-----------------------------------------------------------
DB21061E Command line environment not initialized.
while trying to execute the program.
Is there any way where, we can initialze the Command Line from the window itself?
i.e if I issue an "db2cmd" command in my command prompt I get a new DB2CLP window. My commands should be executed in the DB2CLP window and not in general command prompt.
You did not mention which OS you are running. If you are on Windows,
open the DB2 "Command Window" and run you app there. If you are on Linux, run the app under the instance owner (usually db2inst1).
Hi Andy,
I am using an Windows machine.
When I do a RunTime.getRunTime().exec("db2cmd");
a new window is opened but at the same time it's a different process that has been created, I need to pass new commands to that process.
How can I do that?
You are executing the db2cmd which brings up another DB2 Command Window. What you want to do is execute the DB2 commands directly. Your Java code should look like this:
importRunTime = Runtime.getRuntime();
importChild = importRunTime.exec("CONNECT TO MyDB");
inStream = new java.io.InputStreamReader(importChild.getInputStre am());
buffReader = new java.io.BufferedReader(inStream);
while ((inLine = buffReader.readLine()) != null) {
System.out.println(inLine);
}
exitVal = importChild.waitFor();
importChild = importRunTime.exec("EXPORT TO ...");
inStream = new java.io.InputStreamReader(importChild.getInputStre am());
buffReader = new java.io.BufferedReader(inStream);
while ((inLine = buffReader.readLine()) != null) {
System.out.println(inLine);
}
exitVal = importChild.waitFor();
Then this is how it works:
1) open a new DB2 command window from the desktop.
2) execute you program from here
3) the rest should work,