spark-sql jdbc操作mysql

  SparkConf sparkConf = new SparkConf()
.setMaster("local")
.setAppName("MySqlTest"); JavaSparkContext javaSparkContext = new JavaSparkContext(sparkConf); SQLContext sqlContext = new SQLContext(javaSparkContext); Properties properties = new Properties();
properties.setProperty("driver", "com.mysql.jdbc.Driver");
properties.setProperty("user", "root");
properties.setProperty("password", "123456"); DataFrame df_jdbc = sqlContext.read().jdbc("jdbc:mysql://127.0.0.1:3306/bi?characterEncoding=utf8", "customer", properties); DataFrame df_jdbc_single_col = df_jdbc.select("cusCode");
df_jdbc_single_col.show(); //保存=====================
Map<String, String> map = new HashMap<String, String>();
map.put("driver", "com.mysql.jdbc.Driver");
map.put("user", "root");
map.put("password", "123456"); df_jdbc_single_col.write().options(map).jdbc("jdbc:mysql://127.0.0.1:3306/bi?characterEncoding=utf8", "customer_one_col", properties);
//=======================
上一篇:由清除float原理到BFC


下一篇:sed删除空行和开头的空格和tab键