读取Mysql数据 object JdbcRDDDemo { def getConn() = { Class.forName("com.mysql.jdbc.Driver").newInstance() D
读取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
}
}
--结束END--
本文标题: Spark读取Mysql,Redis,Hbase数据(一)
本文链接: https://www.lsjlt.com/news/5992.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-14
2024-05-14
2024-05-14
2024-05-14
2024-05-14
2024-05-14
2024-05-14
2024-05-14
2024-05-14
2024-05-14
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0