数据库
首页 > 数据库> > 从关系型数据库中创建DataFrame

从关系型数据库中创建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()
  }
}

标签:jdbc,val,创建,数据库,DataFrame,mysql,put,new,properties
来源: https://www.cnblogs.com/jsqup/p/16630334.html