Solved

Run sqlldr in java

Posted on 2004-10-11
5
1,499 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Fibonacci challenge 11 84
strDist challenge 35 84
mapShare challenge 13 70
mapAB Challlenge 35 89
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now