Solved

Run sqlldr in java

Posted on 2004-10-11
5
1,625 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 500 total points
ID: 12280475
Try with the code i posted
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12280861
8-)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 51
How to convert from xls to xlsx using java 7 54
eclipse console opening separately 2 29
ejb mdb examples 1 6
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

792 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