从关系型数据库中创建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()
}
}
本文来自博客园,作者:jsqup,转载请注明原文链接:https://www.cnblogs.com/jsqup/p/16630334.html