- 说明:
/*
需要引入依赖
<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()
}
}
标签:jdbc,val,创建,数据库,DataFrame,mysql,put,properties
From: https://www.cnblogs.com/jsqup/p/16630334.html