Spark SQL Dataframe 写入oracle
可以看此处文章https://xvlvzhu.github.io/2018/01/07/Spark%E6%93%8D%E4%BD%9C%E6%95%B0%E6%8D%AE%E5%BA%93%E7%A4%BA%E4%BE%8B/以下是写入Oracle数据库val url = "jdbc:oracle:thin:@//ip:1521/数据库名称"val user = "ods"val password
·
可以看此处文章https://xvlvzhu.github.io/2018/01/07/Spark%E6%93%8D%E4%BD%9C%E6%95%B0%E6%8D%AE%E5%BA%93%E7%A4%BA%E4%BE%8B/
以下是写入Oracle数据库
val url = "jdbc:oracle:thin:@//ip:1521/数据库名称"
val user = "ods"
val password = "oracle"
val driver = "oracle.jdbc.driver.OracleDriver"
val dbmap = Map("url" -> url, "user" -> user, "password" -> password, "driver" -> driver)
val properties = new Properties()
properties.setProperty("url", url)
properties.setProperty("user", user)
properties.setProperty("password", password)
properties.setProperty("driver", driver)
def saveSummary(rowrdd: RDD[Row], sqlContext: SQLContext): Unit = {
//DateTypes.createStructField()
val schema= StructType(List(StructField("mon_th",IntegerType, true)
, StructField("current_date", DateType, true)
, StructField("amount", DoubleType, true)
, StructField("account_code", StringType, true)
, StructField("summary_code", StringType, true)
, StructField("project", StringType, true)
))
val dataFrame=sqlContext.createDataFrame(rowrdd,schema)
dataFrame.show()
dataFrame.write.mode(SaveMode.Append).jdbc(url,"表名",properties)
}

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐
所有评论(0)