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.

 
Go Back  dBforums > Database Server Software > DB2 > using export or import from java

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-03-06, 06:04
Ayusman Ayusman is offline
Registered User
 
Join Date: Nov 2005
Posts: 16
using export or import from java

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.

please advise,
regards
Ayusman
Reply With Quote
  #2 (permalink)  
Old 08-03-06, 08:13
rahul_s80 rahul_s80 is offline
Registered User
 
Join Date: Jul 2006
Location: Pune , India
Posts: 433
hi there
I dont think that would be a problem (even though i know only basics of java ).You will find many examples on java programs at

...IBM\SQLLIB\samples\java\jdbc

there are many examples and examning them make me believe that its not a very big task

Rahul Singh
Reply With Quote
  #3 (permalink)  
Old 08-03-06, 08:22
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
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:

http://db2.mi.hdm-stuttgart.de/db2he...stats-java.htm

http://www.javaworld.com/javaforums/...sb=3&o=&fpart=

The exapmle are for the runstats utility, but you just change it to the import/export utility to get it to work.

HTH

Andy
Reply With Quote
  #4 (permalink)  
Old 08-03-06, 09:38
Ayusman Ayusman is offline
Registered User
 
Join Date: Nov 2005
Posts: 16
Thanks...

Hi Rahul,Andy

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.

Can you please suggest on this.

Thanks in advance
Ayusman
Reply With Quote
  #5 (permalink)  
Old 08-03-06, 10:12
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
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).

HTH

Andy
Reply With Quote
  #6 (permalink)  
Old 08-03-06, 11:25
Ayusman Ayusman is offline
Registered User
 
Join Date: Nov 2005
Posts: 16
export on windows

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?

Kindly advise.

Regards
Ayusman
Reply With Quote
  #7 (permalink)  
Old 08-03-06, 11:41
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
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,

Andy
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On