Spark 1.6 (Java) 问题汇总
2016-06-02 10:35
381 查看
一、通过SparkSQL读取Oracle时报找不到Oracle JDBC包 (java.lang.ClassNotFoundException:oracle.jdbc.driver.OracleDriver)
说明:程序是本地通过Java将Spark提交给集群运行,但是集群上面没有Oracle JDBC包
解决方法:
官网对于集群运行JDBC的说明:
Troubleshooting
The JDBC driver class must be visible to the primordial class loader on the client session and on all executors. This is because Java’s DriverManager class does a security check that results in it ignoring all drivers not visible to the primordial classloader when one goes to open a connection. One convenient way to do this is to modify compute_classpath.sh on all worker nodes to include your driver JARs.
但是在/etc/profile文件中添加jar路径并没有效果
最终找到方法需要在代码中指定Worker的jar依赖,当然jar包已经上传到每台Worker上,代码如下:
SparkConf conf = new SparkConf().setAppName("Test").setMaster("spark://master2:7077"); <span style="font-size:14px;color:#ff0000;">conf.set("spark.driver.extraClassPath", "/data/ojdbc14-10.2.0.3.0.jar"); conf.set("spark.executor.extraClassPath", "/data/ojdbc14-10.2.0.3.0.jar");</span> JavaSparkContext sparkContext = new JavaSparkContext(conf); sparkContext.hadoopConfiguration().set("fs.defaultFS", "hdfs://mycluster"); sparkContext.hadoopConfiguration().set("dfs.nameservices", "mycluster"); sparkContext.hadoopConfiguration().set("dfs.ha.namenodes.mycluster", "nn1,nn2"); sparkContext.hadoopConfiguration().set("dfs.namenode.rpc-address.mycluster.nn1", "xx.xx.xx.xxx:8020"); sparkContext.hadoopConfiguration().set("dfs.namenode.rpc-address.mycluster.nn2", "xx.xx.xx.xxx:8020"); sparkContext.hadoopConfiguration().set("dfs.client.failover.proxy.provider.mycluster","org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider"); SQLContext sqlContext = new SQLContext(sparkContext); Map<String, String> options = new HashMap<String, String>(); options.put("url", "jdbc:oracle:thin:mioclub/mioclub3728@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=myrac-scan.mic.com.tw)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=myrac.mic.com.tw)))"); options.put("dbtable", "mio_login_transfer"); options.put("driver", "oracle.jdbc.driver.OracleDriver"); DataFrame jdbcDF = sqlContext.read().format("jdbc"). options(options).load(); Row a = jdbcDF.first(); DataFrame d2 = jdbcDF.limit(10); d2.rdd().saveAsTextFile("/Test/sql.txt");
相关文章推荐
- Patrol 7 架构下?的处理方法
- 中病毒后常用的解决方法病毒终极解决方案
- QQ尾巴 InfoMs.Ime 解决方案
- IE对CSS样式表的限制分析与解决方案
- 开源MySQL高效数据仓库解决方案:Infobright详细介绍
- 惊现支撑1亿pv/天的超级数据库解决方案
- 关于bluehost空间上wordpress后台变为英文的解决方案
- select * from sp_who的解决方案
- 简析Oracle数据库常见问题及解决方案
- php+mysql大量用户登录解决方案分析
- 常见PHP数据库解决方案分析介绍
- asp.net操作过程中常见错误的解决方法
- JSP页面显示中文乱码的解决方案
- NFrame——敏捷服务器开发解决方案简介
- Window phone用手机来控制电脑的多媒体播放
- Linux中文文件显示乱码或Secure CRT显示乱码解决方案
- VERITAS的全线产品解决方案介绍
- Vmware安装报msi错误解决方案(官方翻译中文版)
- 鸿博信通云交换机(云PBX)
- java读取excel之poi