线程“main”java.sql.SQLException 中的异常:运行 spark-submit 时没有合适的驱动程序
Posted
技术标签:
【中文标题】线程“main”java.sql.SQLException 中的异常:运行 spark-submit 时没有合适的驱动程序【英文标题】:Exception in thread "main" java.sql.SQLException: No suitable driver while running spark-submit 【发布时间】:2018-07-20 06:55:38 【问题描述】:Spark 版本:2.3.0
我正在使用 --jars
选项运行 spark-submit 命令。
我已经在命令中提供了ojdbc6.jar,如下图。
命令
./spark-submit --class com.sample.ABC --jars /scratch/user/abc/drools-jars/ojdbc6.jar --master spark://IP:Port "/scratch/user/abc/POC jar/ABC-0.0.1-SNAPSHOT.jar"
我仍然遇到异常:
Exception in thread "main" java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:315)
at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions$$anonfun$7.apply(JDBCOptions.scala:85)
at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions$$anonfun$7.apply(JDBCOptions.scala:85)
at scala.Option.getOrElse(Option.scala:121)
at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions.<init>(JDBCOptions.scala:84)
at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions.<init>(JDBCOptions.scala:35)
at org.apache.spark.sql.execution.datasources.jdbc.JdbcRelationProvider.createRelation(JdbcRelationProvider.scala:34)
at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:340)
at org.apache.spark.sql.DataFrameReader.loadV1Source(DataFrameReader.scala:239)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:227)
at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:164)
at com.sample.Transformation.main(Transformation.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.spark.deploy.JavaMainApplication.start(SparkApplication.scala:52)
at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:879)
at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:197)
at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:227)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:136)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
【问题讨论】:
【参考方案1】:在命令中添加--driver-class-path
,如下所示:
./spark-submit --class com.sample.ABC --jars /scratch/user/abc/drools-jars/ojdbc6.jar `--driver-class-path /scratch/user/abc/drools-jars/ojdbc6.jar --master spark://IP:Port "/scratch/user/abc/POC jar/ABC-0.0.1-SNAPSHOT.jar"
这解决了问题。
【讨论】:
以上是关于线程“main”java.sql.SQLException 中的异常:运行 spark-submit 时没有合适的驱动程序的主要内容,如果未能解决你的问题,请参考以下文章