Results 1 to 7 of 7
  1. #1
    Join Date
    Nov 2005
    Posts
    16

    Unanswered: 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

  2. #2
    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

  3. #3
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    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

  4. #4
    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

  5. #5
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    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

  6. #6
    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

  7. #7
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •