在spark2 scala中找不到com.mysql.jdbc.Driver

时间:2019-03-14 03:09:01

标签: mysql apache-spark-2.0

我正在使用具有Scala内核的Jupyter Notebook,下面是将mysql表导入数据框的代码:

val sql="""select * from customer"""
val df_customer = spark.read
  .format("jdbc")
  .option("url", "jdbc:mysql://localhost:3306/ccfd")
  .option("driver", "com.mysql.jdbc.Driver")
  .option("dbtable",  s"( $sql ) t")
  .option("user", "root")
  .option("password", "xxxxxxx")
  .load()

以下是错误:

Name: java.lang.ClassNotFoundException
Message: com.mysql.jdbc.Driver
StackTrace:   at scala.reflect.internal.util.AbstractFileClassLoader.findClass(AbstractFileClassLoader.scala:62)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  at org.apache.spark.sql.execution.datasources.jdbc.DriverRegistry$.register(DriverRegistry.scala:45)
  at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions$$anonfun$6.apply(JDBCOptions.scala:79)
  at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions$$anonfun$6.apply(JDBCOptions.scala:79)
  at scala.Option.foreach(Option.scala:257)
  at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions.<init>(JDBCOptions.scala:79)
  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)

任何人都可以在此处共享有效的代码段吗?我正在使用Spark2,在新笔记本中启动内核时,名为spark的会话已准备就绪。

谢谢。

0 个答案:

没有答案