Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Map;
  3.  
  4. import org.apache.spark.SparkConf;
  5. import org.apache.spark.SparkContext;
  6. import org.apache.spark.sql.SQLContext;
  7.  
  8.  
  9.  
  10. public class caricaDati {
  11.  
  12. public static void main(String[] args) {
  13. Map<String, String> options = new HashMap<String, String>();
  14. options.put("url",
  15. "jdbc:mysql://localhost:3306/banche?user=..&password=...");
  16. options.put("dbtable", "t_analisi_banche_021");
  17. SparkContext sc = new SparkContext(new SparkConf().setAppName("DBConnection").setMaster("local[*]"));
  18. SQLContext sqlContext = new org.apache.spark.sql.SQLContext(sc);
  19. DataFrame jdbcDF = sqlContext.read.format("jdbc").options(options);
  20. System.out.println("Data------------------->" + jdbcDF.toJSON().first());
  21. Row[] rows = jdbcDF.collect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement