当前位置: 移动技术网 > IT编程>数据库>其他数据库 > Spark读取Mysql,Redis,Hbase数据

Spark读取Mysql,Redis,Hbase数据

2020年05月11日  | 移动技术网IT编程  | 我要评论

九年级上册英语视频,清除甲醛,帷千动媒

1、读取mysql数据

object jdbcrdddemo {

  def getconn() = {
    class.forname("com.mysql.jdbc.driver").newinstance()
    drivermanager.getconnection("jdbc:mysql://hadoop000:3306/hive", "root", "root")
  }

  def main(args: array[string]): unit = {
    val sparkconf = new sparkconf().setappname("jdbcrdd").setmaster("local[*]")
    val sc = new sparkcontext(sparkconf)

    val jdbcrdd = new jdbcrdd(
      sc,
      getconn,
      "select * from tbls where tbl_id >= ? and tbl_id <= ?",
      1,
      10,
      2,
      rs => {
        val id = rs.getint(1)
        val name = rs.getstring(2)
        val age = rs.getint(3)
        (id,name,age)
      }
    )

    jdbcrdd.collect().tobuffer
  }
}

转自:https://www.cnblogs.com/hgc-bky/p/12863544.html

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网