百度其他资料,都说是因为$HADOOP-YARN-HOME下没有驱动包,查看他们源码 其实是代码没有加载驱动
贴正确代码
package l847164916 import java.util.Properties import org.apache.calcite.avatica.Meta.ConnectionProperties import org.apache.spark.sql.{SQLContext, SaveMode} import org.apache.spark.sql.hive.HiveContext import org.apache.spark.{SparkConf, SparkContext} /** * Created by Administrator on 2016/8/25. */ object Hive2MySql { def main(args: Array[String]): Unit = { val url = "" val prop = new Properties() prop.setProperty("user","") prop.setProperty("password","") prop.setProperty("driver","com.mysql.jdbc.Driver") val conf = new SparkConf().setAppName("hive2mysql") val sc = new SparkContext(conf) val hict = new HiveContext(sc) hict.sql("use dwb") val df = hict.sql("select ldap_dn,mail_name,mobile,domain_name,email,office_code,cn_name,title from index_emp_info") df.printSchema() df.write.mode(SaveMode.Append).jdbc(url,"base_info",prop) } }