Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Run sqlldr in java

Posted on 2004-10-11
5
Medium Priority
?
2,069 Views
Last Modified: 2012-08-14
I want to run sqlldr on my machine. I use the code below:

public void doSqlLoader(){
       String s = null;            
       try {
      System.out.println("Starting SQLLOAD");
      String cmd = "sqlldr owner/owner@trdbd control=C:\\nd\\iaf.ctl  
                                 data=C:\\nd\\iaf_account_20040929.txt log=C:\\nd\\transfer.log errors=10000";
            
      Process p = Runtime.getRuntime().exec("cmd");
       p.waitFor();
       BufferedReader stdInput = new BufferedReader(new
       InputStreamReader(p.getInputStream()));
                  
       BufferedReader stdError = new BufferedReader(new
       InputStreamReader(p.getErrorStream()));

       // read the output from the command          
      
      while ((s = stdInput.readLine()) != null) {
               System.out.println(s);
       }
           
       // read any errors from the attempted command
       System.out.println("Here is the standard error of the command (if any):\n");
       while ((s = stdError.readLine()) != null) {
               System.out.println(s);
       }
         if ( p.exitValue() ==0)
         {
               System.out.println("\n\nSQLLOAD completed.");
          }
               } catch (IOException ioe){
                       System.out.println(ioe);
               }catch (InterruptedException ie){
         System.out.println(ie);
               }
}

It doesn't work and never generate a log file. Could you please help me for that?
Thanks.
                                        
0
Comment
Question by:jen2483
  • 4
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12280303
>>It doesn't work

Meaning?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12280409
Try

final String[] cmd = {
      "sqlldr",
      "owner/owner@trdbd",
      "control=C:\\nd\\iaf.ctl",
      "data=C:\\nd\\iaf_account_20040929.txt",
      "log=C:\\nd\\transfer.log errors=10000" };
RunAsync.main(cmd);      

with the following class:


//SNIP===============================================================

import java.io.*;

/**
 *  Description of the Class
 *
 * @author     Administrator
 * @created    23 February 2004
 */
public class RunAsync {

  /**
   *  Description of the Method
   *
   * @param  args  Description of the Parameter
   */
  public static void main(String args[]) {

    try {

      if (args.length < 1) {
        System.out.println("Usage: java RunAsync <command string>");
        System.exit(-1);
      }
      Process pro = null;
      if (args.length > 1) {
        pro = Runtime.getRuntime().exec(args);
      }
      else {
        pro = Runtime.getRuntime().exec(args[0]);
      }
      InputStream error = pro.getErrorStream();
      InputStream output = pro.getInputStream();
      Thread err = new Thread(new OutErrReader(error));
      Thread out = new Thread(new OutErrReader(output));
      out.start();
      err.start();
      pro.waitFor();
    }
    catch (java.io.IOException e) {
      e.printStackTrace();
    }
    catch (java.lang.InterruptedException e) {
      e.printStackTrace();
    }

  }


  /**
   *  Description of the Class
   *
   * @author     Administrator
   * @created    23 February 2004
   */
  static class OutErrReader implements Runnable {
    InputStream is;


    /**
     *Constructor for the OutErrReader object
     *
     * @param  is  Description of the Parameter
     */
    public OutErrReader(InputStream is) {
      this.is = is;
    }


    /**
     *  Main processing method for the OutErrReader object
     */
    public void run() {
      try {
        BufferedReader in = new BufferedReader(new InputStreamReader(is));
        String temp = null;
        while ((temp = in.readLine()) != null) {
          System.out.println(temp);
        }
        is.close();
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
}

0
 

Author Comment

by:jen2483
ID: 12280441
If it works, it should generate a log file under the directory I defined as C:\nd\transfer.log and the data should be insert into the table of the database. Now the code doesn't accomplish these purposes.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 12280475
Try with the code i posted
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12280861
8-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question