Advertisement
Guest User

Untitled

a guest
Sep 1st, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. import org.apache.spark.{SparkContext,SparkConf}
  2. import org.apache.spark.sql.hive.HiveContext
  3.  
  4. //Do add the following artifact in build.sbt
  5. //libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.43"
  6.  
  7. //initializations
  8. val conf = new SparkConf().setAppName("xx").setMaster("local[2]")
  9. val sc = new SparkContext(conf)
  10.  
  11. val hiveContext = new HiveContext(sc)
  12. // can use sqlContext as well (i.e. sparkSQL in native context)
  13.  
  14. val prop = new java.util.Properties
  15.  
  16. prop.setProperty("user","root")
  17. prop.setProperty("password","XXX")
  18. val df_mysql = hiveContext.read.jdbc("jdbc:mysql://localhost:3306/retail_db","products",prop)
  19. df_mysql.show
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement