本文主要是介绍从关系型数据库中创建DataFrame,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
/*
需要引入依赖
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.18</version>
</dependency>
*/
object MySQLToDataFrame {
def main(args: Array[String]): Unit = {
val sc = new SparkConf().setMaster("local[2]").setAppName("demo")
val session = SparkSession.builder().config(sc).getOrCreate()
val properties = new Properties()
properties.put("driver", "com.mysql.cj.jdbc.Driver")
properties.put("user", "root")
properties.put("password", "Jsq123456...")
val dataFrame = session.read.jdbc("jdbc:mysql://node1:3306/project?serverTimeznoe=UTC", "area_pvs", properties)
dataFrame.show()
}
}
这篇关于从关系型数据库中创建DataFrame的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!