Spark Unable to find JDBC Driver

前端 未结 10 2199
栀梦
栀梦 2020-11-28 08:47

So I\'ve been using sbt with assembly to package all my dependencies into a single jar for my spark jobs. I\'ve got several jobs where I was using c3p0 to setu

10条回答
  •  离开以前
    2020-11-28 09:10

    There exists a simple Java trick to solve your problem. You should specify Class.forName() instance. For example:

     val customers: RDD[(Int, String)] = new JdbcRDD(sc, () => {
           Class.forName("com.mysql.jdbc.Driver")
           DriverManager.getConnection(jdbcUrl)
          },
          "SELECT id, name from customer WHERE ? < id and id <= ?" ,
          0, range, partitions, r => (r.getInt(1), r.getString(2)))
    

    Check the docs

提交回复
热议问题