import org.apache.spark.sql.SaveMode
// Write out and create the table as well to mysql via DF Writer API
val RDD = spark.sparkContext.parallelize(Seq(
("A2", "X", "done"),
("A2", "Y", "done"),
("C2", "Y", "done"),
("B2", "Y", "done"),
("Z2", "Z", "done")
))
val jdbcDF = RDD.toDF("Company", "Type", "Status")
// Saving data to a JDBC source - creates the table as well
jdbcDF.write
.format("jdbc")
.option("url", "jdbc:mysql://db4free.net:3306/mySQLDB")
.option("dbtable", "tabname")
.option("user", "xxx")
.option("password", "yyy")
//.save()
.mode(SaveMode.Append)
1条答案
按热度按时间3bygqnnd1#
一个可能的例子,但这里有一个风格让你去:
你可能需要设置驱动程序,因为我在databricks下运行了这个。