您的位置:首页 > 数据库 > MySQL

sparkStreaming连接数据库(mysql)

2017-09-08 11:17 423 查看
通过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操作;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: