Solved

Run sqlldr in java

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

912 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

16 Experts available now in Live!

Get 1:1 Help Now