sparkStreaming连接数据库(mysql)

时间:2021-10-10 02:54:36

通过SparkStreaming读取mysql数据库表数据jon另一张表

SparkConf conf = new SparkConf().setAppName("JDBCDataSource")
.setMaster("local");
JavaSparkContext sc = new JavaSparkContext(conf);
@SuppressWarnings("deprecation")
SQLContext sqlcontext = new SQLContext(sc);


// 分别将mysql中两张表的数据加载为dataset
Map<String, String> options = new HashMap<String, String>();
options.put("url", "jdbc:mysql://IP:3306/testdb");
options.put("driver", "com.mysql.jdbc.Driver") ; 
options.put("user", "root");
options.put("password", "cys");
options.put("dbtable", "student_infos");
options.put("dbtable", "student_scores");


Dataset<Row> studentsInfosDS = sqlcontext.read().format("jdbc").options(options).load();
Dataset<Row> studentScoreDS = sqlcontext.read().format("jdbc").options(options).load();

。。。。t通过Dataset<Row> 的RDD对表数据join操作;