Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Map;
- import org.apache.spark.SparkConf;
- import org.apache.spark.SparkContext;
- import org.apache.spark.sql.SQLContext;
- public class caricaDati {
- public static void main(String[] args) {
- Map<String, String> options = new HashMap<String, String>();
- options.put("url",
- "jdbc:mysql://localhost:3306/banche?user=..&password=...");
- options.put("dbtable", "t_analisi_banche_021");
- SparkContext sc = new SparkContext(new SparkConf().setAppName("DBConnection").setMaster("local[*]"));
- SQLContext sqlContext = new org.apache.spark.sql.SQLContext(sc);
- DataFrame jdbcDF = sqlContext.read.format("jdbc").options(options);
- System.out.println("Data------------------->" + jdbcDF.toJSON().first());
- Row[] rows = jdbcDF.collect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement