Spark教程
1、
package com.k6k4 import java.util.Properties import org.apache.spark.SparkConf import org.apache.spark.sql.SparkSession /** * Created by k6k4 on 16/12/13. */ object MysqlTest { def main(args: Array[String]) { val sparkConf = new SparkConf().setAppName("MysqlTest"). setMaster("local[2]") val spark = SparkSession .builder() .config(sparkConf) .getOrCreate(); val prop = new Properties; prop.setProperty("user", "root"); prop.setProperty("password", "root") val table = spark.read.jdbc("jdbc:mysql://localhost:3306/dbName", "tableName", prop) val custinfo = table. select("name", "age") .where("id=1"); val rows = custinfo.collect(); rows.foreach(row => { println(row.getString(0) + "\t" + row.getLong(1)) } ) spark.stop(); } }
2、