使用 ojdbc6 连接器导入 Sqoop
Posted
技术标签:
【中文标题】使用 ojdbc6 连接器导入 Sqoop【英文标题】:Sqoop import using ojdbc6 connector 【发布时间】:2017-04-05 10:07:29 【问题描述】:我正在使用 sqoop 从 oracle 11g 导入数据,因为我无权将 ojdbc jar 放入集群上的 sqoop 的 lib 中,我明确使用 -libjars 提供了 jar,但它抛出异常。我拥有的代码使用的是:
sqoop eval -libjars /root/shared_folder/ojdbc6.jar --driver oracle.jdbc.OracleDriver --connect jdbc:oracle:thin:@127.0.0.1:1521:XE --username srivastavaaman --password manager --query 'SELECT * from TestTable1'
接下来的输出是:
Warning: /usr/lib/sqoop/../accumulo does not exist! Accumulo imports will fail.
Please set $ACCUMULO_HOME to the root of your Accumulo installation.
17/04/05 02:48:40 INFO sqoop.Sqoop: Running Sqoop version: 1.4.4.2.1.1.0-385
17/04/05 02:48:41 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.
17/04/05 02:48:41 WARN sqoop.ConnFactory: Parameter --driver is set to an explicit driver however appropriate connection manager is not being set (via --connection-manager). Sqoop is going to fall back to org.apache.sqoop.manager.GenericJdbcManager. Please specify explicitly which connection manager should be used next time.
17/04/05 02:48:41 INFO manager.SqlManager: Using default fetchSize of 1000
17/04/05 02:48:41 ERROR sqoop.Sqoop: Got exception running Sqoop: java.lang.RuntimeException: Could not load db driver class: oracle.jdbc.OracleDriver
java.lang.RuntimeException: Could not load db driver class: oracle.jdbc.OracleDriver
at org.apache.sqoop.manager.SqlManager.makeConnection(SqlManager.java:797)
at org.apache.sqoop.manager.GenericJdbcManager.getConnection(GenericJdbcManager.java:52)
at org.apache.sqoop.tool.EvalSqlTool.run(EvalSqlTool.java:64)
at org.apache.sqoop.Sqoop.run(Sqoop.java:147)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
at org.apache.sqoop.Sqoop.runSqoop(Sqoop.java:183)
at org.apache.sqoop.Sqoop.runTool(Sqoop.java:222)
at org.apache.sqoop.Sqoop.runTool(Sqoop.java:231)
at org.apache.sqoop.Sqoop.main(Sqoop.java:240)
如果相同的 ojdbc6.jar 放在本地机器的 sqoop 的 lib 中,它可以正常工作。
【问题讨论】:
【参考方案1】:-libjars
参数通常不与 Sqoop 一起使用,而是作为 Hadoop 内部参数解析系统的一部分添加。
将 Jar 文件的路径附加到 $HADOOP_CLASSPATH
变量中。
export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:/root/shared_folder/ojdbc6.jar
sqoop eval --driver oracle.jdbc.OracleDriver --connect jdbc:oracle:thin:@127.0.0.1:1521:XE --username ****** --password ***** --query 'SELECT * from TestTable1'
【讨论】:
以上是关于使用 ojdbc6 连接器导入 Sqoop的主要内容,如果未能解决你的问题,请参考以下文章