Ich habe dieses Problem. IDE Scala gibt mir einen Fehler, weil es besagt, dass read
Methode in sqlContext.read.format("jdbc").options(options)
nicht zu SQLContext
Objekt gehört. Muss ich eine Abhängigkeit hinzufügen?Laden Sie Daten von Mysql-Datenbank mit Hilfe von Scala IDE im Spark-Framework
Dann weiß ich nicht, welche Bibliothek ich für die DataFrame
und Objekt hinzufügen muss.
Dies ist der Code.
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();
}
}