I know how to use sqoop through command line. But dont know how to call sqoop command using java programs . Can anyone give some code view?
Question&Answers:osI know how to use sqoop through command line. But dont know how to call sqoop command using java programs . Can anyone give some code view?
Question&Answers:osYou can run sqoop from inside your java code by including the sqoop jar in your classpath and calling the Sqoop.runTool()
method. You would have to create the required parameters to sqoop programmatically as if it were the command line (e.g. --connect
etc.).
Please pay attention to the following:
Sqoop.runTool()
as opposed to Sqoop.Main()
is the fact that runTool()
return the error code of the execution.Hope that helps.
final int ret = Sqoop.runTool(new String[] { ... });
if (ret != 0) {
throw new RuntimeException("Sqoop failed - return code " + Integer.toString(ret));
}
RL