Below program in completly executing but no data was inserted through sqlloader.

Inline Code Example Here


public class CSVDataLoad {
    public void runSqlldr () throws InterruptedException {
        String[] stringCommand = { "bash", "-c", "/usr/bin/sqlldr username/password@sid control=/path/to/sample.ctl"};
        System.out.println("SQLLDR Started");
        Runtime rt = Runtime.getRuntime();
        Process proc = null;
        try {
                proc = rt.exec(stringCommand);
        }catch (IOException e) {
                e.printStackTrace();
        } catch (NullPointerException e) {
                e.printStackTrace();
        }finally {
                proc.destroy();
        }
        System.out.println("SQLLDR Ended");
}

public static void main(String[] args) {
        try {
                new CSVDataLoad().runSqlldr();
        } catch(InterruptedException e) {
                e.printStackTrace();
        }
}

`

and how do you expect us to help ? you assume we know the contents of your local files ?
what data are you expecting ?
how do you know nohthing is inserted ? have you checked whether or not the code you are calling works the way it should ? or that your sample file is as you expect it ?

I have written the below piece of code, this is working fine if file to load is small , but if i process a large file for example of 3k records , the process get hangs and no error is printed.
Data in table get loaded to few records and the process thread stucks.

Any help will be appriciated.

package sqlloader;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

class sqlldr
{
public static void main(String cmd[]) throws IllegalThreadStateException {
String str = "sqlldr" + " " + "username" + "/" + "password" + "@" +"//"+ "ipofdb"+":"+"port"+"/"+ "domain"
        + " " + "control=" + "name.ctl" ;
try {
System.out.println("\nexecuting process() ......");

Process process_bcp = Runtime.getRuntime().exec(str);

InputStream stderr = process_bcp.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
System.out.println("<ERROR>");
while ( (line = br.readLine()) != null)
    System.out.println(line);
System.out.println("</ERROR>");
int exitVal = process_bcp.waitFor();
System.out.println("Process exitValue: " + exitVal);
int returnValue = process_bcp.exitValue();

System.out.println("\nin runBCP(), returnValue = " +returnValue);
if(returnValue != 0) {
InputStream in = process_bcp.getInputStream();
InputStreamReader preader = new InputStreamReader(in);
BufferedReader breader= new BufferedReader(preader);
String msg = null;
while((msg = breader.readLine()) != null) {
System.out.println(msg);
str += "" + msg + "";
}
System.out.flush();
preader.close();
breader.close();
in.close();

InputStream inError = process_bcp.getErrorStream();
InputStreamReader preaderError = new InputStreamReader(inError);
BufferedReader breaderError= new BufferedReader(preaderError);

String errorMsg = null;
while((errorMsg = breaderError.readLine()) != null) {
System.out.println("Copy Error: " + errorMsg);
str += "" + errorMsg + "";
}
System.out.flush();
preaderError.close();
breaderError.close();
inError.close();
}
else{

InputStream in = process_bcp.getInputStream();
InputStreamReader preader = new InputStreamReader(in);
BufferedReader breader= new BufferedReader(preader);
String msg = null;
while((msg = breader.readLine()) != null) {
System.out.println(msg);
str += "" + msg + "";
}
System.out.flush();
preader.close();
breader.close();
in.close();
}
process_bcp.destroy();

System.out.println("IMPORT PORTFOLIO DATA DONE");
}catch(InterruptedException e){
System.out.println("Exception : " + e.toString());
e.printStackTrace();
str = "UPLOAD FAILED";
}catch(Exception e){
str = "UPLOAD FAILED";
System.out.println("Exception : " + e.toString());
e.printStackTrace();
}
System.out.println(str);

}
} 

The same command executed from terminal is successfully uploads data in db.

Excellent. It works perfectly on my computer (java 1.7)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.