Solved

Run sqlldr in java

Posted on 2004-10-11
5
1,699 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
web application structure 18 135
Running JavaFX on JDeveloper 12C 1 116
ejb entity bean example 2 57
web project error add remove 1 85
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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…
Suggested Courses

752 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