Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2003
    Posts
    13

    Unanswered: Export command with Java SQL

    Hi!

    I'm using JDBC 2.0 to access a DB2 database from a Java application.
    I should export the entire table in IXF format so I wanted to use the export command as in the following example:

    Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").ne wInstance();
    con = DriverManager.getConnection(url);
    stmt = con.createStatement();
    stmt.execute ("EXPORT TO 'C:"+File.separator+"MyTable.ixf' OF IXF SELECT * FROM MyTable");

    But I get an error message:

    COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/NT] SQL0104N An unexpected token "EXPORT TO 'C:\MyTable.ixf" was found following "BEGIN-OF-STATEMENT". Expected tokens may include: "<from>". SQLSTATE=42601


    Does anyone know how to export a table in a Java program?

    Thanks,

    Cesar

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5

    Re: Export command with Java SQL

    Yes.
    First you need to run the java program from the DB2 command window. Second instead of trying to execute the EXPORT as SQL (it isn't by the way, it is a command--hence your error), run the export as a java child process: "DB2 EXPORT to .... ". You can use this method
    for any DB2 command.

    Look at this web site for sample code:

    http://www.developer.ibm.com/tech/sampdb2.html

    And look at the one listed as:

    Java sample code to demonstrate running Runstats (Runstats.zip)

    HTH

    Andy

    Originally posted by cesar
    Hi!

    I'm using JDBC 2.0 to access a DB2 database from a Java application.
    I should export the entire table in IXF format so I wanted to use the export command as in the following example:

    Class.forName("COM.ibm.db2.jdbc.app.DB2Driver").ne wInstance();
    con = DriverManager.getConnection(url);
    stmt = con.createStatement();
    stmt.execute ("EXPORT TO 'C:"+File.separator+"MyTable.ixf' OF IXF SELECT * FROM MyTable");

    But I get an error message:

    COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/NT] SQL0104N An unexpected token "EXPORT TO 'C:\MyTable.ixf" was found following "BEGIN-OF-STATEMENT". Expected tokens may include: "<from>". SQLSTATE=42601


    Does anyone know how to export a table in a Java program?

    Thanks,

    Cesar

  3. #3
    Join Date
    Jun 2008
    Posts
    2

    db2 export command in Java

    Hi,

    I am also having the same problem as above with EXPORT Command. The url that is specified as a solution is not valid. Can you please suggest an alternative...

    Thanks,
    NAVYA

  4. #4
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Quote Originally Posted by navya_nagaraj
    Hi,

    The url that is specified as a solution is not valid. Can you please suggest an alternative...
    That is not surprising since the post is almost 5 years old. You should be able to find a sample .java file in your system. Look in
    c:\program files\ibm\sqllib\samples\java\jdbc\tbrunstats.java

    Andy

  5. #5
    Join Date
    Jun 2008
    Posts
    2
    Hey Andy,

    Thanks a lot !!

    I got the sample code and it works fine now.

    I have one more question for you though.... I had to execute the java program from a db2cmd window by following the sample code.. The program executes only then.
    Is there any way through which I can invoke a db2cmd window from the java program itself ? The whole idea is that I want to export the ixf by hitting a button on a web page and this would of course require my backend process to run in the db2cmd window..

    Can you please suggest me a way to do the above ?

    Thanks,
    Navya

  6. #6
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    db2cmd or a "command window" is simply an OS shell with a profile. If you can have the java program load that profile, then you should be set.

    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
  •