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);
//=======================