English 中文(简体)
由 sqlloader 装入数据时获得通知
原标题:Get notified when loading of data is done by sqlloader

I have a java code through which I call the bat file. This bat file contains call to sqlldr which loads data from a txt file into a table(in oracle). This is the java code to call the bat file

ProcessBuilder pb = new ProcessBuilder(new File(".").getAbsolutePath()
                + File.separator + "ld.bat");
        System.out.println("Before start");
Process start;
            try {
                start = pb.start();


        } catch (IOException e) {

            e.printStackTrace();
        } 

Below this code I am creating new threads and doing my other tasks. The loading of data takes place in the background. I want to do some task (e.g moving the txt data file to another location) once loading is done. Is there a way to get notified once the loading of data is done by sqlldr. I have come across a work around - I can keep checking the number of rows in d table and compare it with the number of rows in the raw txt file. But I would like to know if there is some another solution for this. Also I dont want to use start.waitFor() as this will keep my other activities on hold.

问题回答

我不确定我完全理解你的问题 - 是否有任何理由 你不能把批量脚本的调用 在一个新的线索中?

例如:

new Thread("Load Data"){
  @Override
  public void run() {
    // load data
    // move txt data file
  }
}.start();

// do other activities 
// (Presumably they re not dependent on the data having been loaded...)

我也有同样的问题 像这样解决

 public void runSqlldr() throws IOException, Exception {
        String sqlldrRunCmd = StartParserEngineHW3G2G.SQLLDRPATH
                + " userid= " + DBHelper.username + "/" + DBHelper.password + "@" + StartParserEngineHW3G2G.TNSNAME + " "
                + " control= " + this.ctlFile.getAbsolutePath() + " "
                + " log= " + this.logFile.getAbsolutePath() + " "
                + " direct=true rows=1000000 errors=1000000000";
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(sqlldrRunCmd);

    while(true){
        if(logFile.exists() && logFile.length() > 0){
            System.out.println(logFile + " is exist and sqlldr completed and lentgh is " + logFile.length());
            proc.destroy();
            break;
        }
        else{
            System.out.println(logFile + " is not exist, and waiting and logfile length is " + logFile.length());
            Thread.sleep(3000);
        }

    }
}

这是精确的解决方案, 已经测试过了 。

当 sqlldr 开始时, 代码下方的代码会等到它结束, 然后执行“ 一些业务 ”

    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(sqlldrRunCmd);
    int exitVal = proc.waitFor();
    System.out.println("Process exitValue: " + exitVal);

    // some business in here




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签