importtool不适用于参数(org.apache.sqoop.sqoopoptions)

xqkwcwgp  于 2021-05-31  发布在  Hadoop
关注(0)|答案(1)|浏览(306)

我们正在尝试使用java进行sqoop导入,在我尝试从importtool中删除不推荐使用的com.cloudera.sqoop.sqoop选项之前,java可以正常工作,如下面的代码段所示。apache.sqoop.sqoopoptions可以替代cloudera.sqoop.sqoopoptions包,但importtool仅支持cloudera包,该包已被弃用。写这段代码的另一种方法是什么?请帮忙。

import org.apache.sqoop.tool.ImportTool;
import org.apache.sqoop.SqoopOptions;
import org.apache.sqoop.SqoopOptions.InvalidOptionsException;
//import com.cloudera.sqoop.SqoopOptions;
//import com.cloudera.sqoop.SqoopOptions.InvalidOptionsException;

public int sqoopImport(String name) throws ThrowIt {
try {
        ImportTool importTool = new ImportTool();
        SqoopOptions sqoopOptions = importTool.parseArguments(arg.toArray(new String[0]), configuration, null,
                true);
        importTool.validateOptions(sqoopOptions); //Error here, ImportTool needs sqoopOption from cloudera which is deprecated.
        returnValue = importTool.run(sqoopOptions); //Error here, ImportTool needs sqoopOption from cloudera which is deprecated.
    }
bvn4nwqk

bvn4nwqk1#

下载这个jar:- enter 此处链接说明
公共类testssh{
public static void main(字符串args[])引发异常{

// Initialize a ConnBean object, the parameter list is IP, username, password

ConnBean cb = new ConnBean("192.168.56.102", "root","hadoop");

// Put the ConnBean instance as parameter for SSHExec static method getInstance(ConnBean) to retrieve a singleton SSHExec instance
SSHExec ssh = SSHExec.getInstance(cb);          
// Connect to server
ssh.connect();
CustomTask sampleTask1 = new ExecCommand("echo $SSH_CLIENT"); // Print Your Client IP By which you connected to ssh server on Horton Sandbox
System.out.println(ssh.exec(sampleTask1));
CustomTask sampleTask2 = new ExecCommand("sqoop import --connect jdbc:mysql://192.168.56.101:3316/mysql_db_name --username=mysql_user --password=mysql_pwd --table mysql_table_name --hive-import -m 1 -- --schema default");
ssh.exec(sampleTask2);
ssh.disconnect();

} }

相关问题