直接上代码:
object JdbcOperation {
def main(args: Array[String]): Unit = {
val conf = new SparkConf().setAppName("test").setMaster("local")
val sc = new SparkContext(conf)
sc.setLogLevel("WARN")
val sqlContext = new SQLContext(sc)
val properties = new Properties()
properties.put("user","test")
properties.put("password","test")
val url = "jdbc:mysql://localhost:3306/test_test"
val stud_scoreDF = sqlContext.read.jdbc(url,"test",properties)
stud_scoreDF.show()
}
}