spark-jdbc No suitable driver found错误处理
程序员文章站
2024-03-14 17:05:46
...
错误如图:
代码:
object Mysql extends App{
val sparkConf = new SparkConf()//.setAppName("RDDRelation").setMaster("local[1]")
val sc=new SparkContext(sparkConf)
val sqlContext = new SQLContext(sc)
sqlContext.setConf("spark.sql.warehouse.dir","file:///")
val url="jdbc:mysql://114.55.96.216:3306/test"
// val url = "jdbc:mysql://114.55.96.216:3306/test?user=test&password=1234"
val prop = new java.util.Properties
prop.setProperty("user","test")
prop.setProperty("password","1234")
//jdbc1*******************
val number=10
val str1=s"userid>$number"
val s=sqlContext.read.format("jdbc").jdbc(url,"userinfo",Array[String](str1),prop).select("username").rdd.distinct().collect()
val s1=s.map(_.toString().replaceAll("\\[|\\]",""))
println("*"*50)
s1.foreach(println(_))
println("*"*50)
//jdbc2*******************
val jdbcDF = sqlContext.read.format("jdbc")
.options(Map("url" -> "jdbc:mysql://114.55.96.216:3306/test",
"driver" -> "com.mysql.jdbc.Driver",
"dbtable" -> "userinfo" ,
"user" -> "test",
"password" -> "1234")).load()
jdbcDF.show()
// sqlContext.read.format("jdbc")
}
依赖:
mysql的jar包在打包时时就已经打进去了,
提交到集群上运行时jdbc1错误。如图1,jdbc2正常
但是jdbc2是拉取整个表的数据,不能条件从数据库查询出部分数据,
解决方法,上传一个 mysql-connector-java-5.1.35.jar至服务器
submit时指定jar包
如:
bin/spark-submit \
--master yarn \
--class test.Mysql \
--driver-class-path /usr/hdp/2.4.0.0-169/spark/lib/mysql-connector-java-5.1.35.jar \
/usr/hdp/2.4.0.0-169/spark/jar/test-scala.jar
,问题解决
上一篇: 【unity】完全新手入门教程----创建项目到控制方块移动
下一篇: 树莓派新手入门教程
推荐阅读
-
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/
-
spark-jdbc No suitable driver found错误处理
-
java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://127.0.0.1:1433;解决...
-
Mybatis 报错java.sql.SQLException: No suitable driver found for http://www.example.com
-
Tomcat启动报错 No suitable driver found for jdbc:mysql://localhost:3306……
-
java.sql.SQLException: No suitable driver found for jdbc:mys_MySQL
-
SSH2+proxool 出现No suitable driver found for proxool.mysqlP
-
java.sql.SQLException: No suitable driver found for jdbc:mi
-
SSH2+proxool 出现No suitable driver found for proxool.mysqlP
-
java.sql.SQLException: No suitable driver found for jdbc:mi