idea中连接mysql获取数据

package com.bawei

import org.apache.flink.api.common.typeinfo.BasicTypeInfo
import org.apache.flink.api.java.io.jdbc.JDBCInputFormat
import org.apache.flink.api.java.typeutils.RowTypeInfo
import org.apache.flink.api.scala._
import org.apache.flink.types.Row
object JDBCSoure {
def main(args: Array[String]): Unit = {
val env = ExecutionEnvironment.getExecutionEnvironment
val unit = MyJDBCRead(env)
unit.print()
}
def MyJDBCRead(env: ExecutionEnvironment): DataSet[Row] ={
env.createInput(JDBCInputFormat.buildJDBCInputFormat()
.setDrivername(“com.mysql.jdbc.Driver”)
.setDBUrl(“jdbc:mysql://hdp111:3306/company”)
.setUsername(“root”)
.setPassword(“000000”)
.setQuery(“select * from staff”)
.setRowTypeInfo(new RowTypeInfo(BasicTypeInfo.INT_TYPE_INFO,
BasicTypeInfo.STRING_TYPE_INFO,BasicTypeInfo.STRING_TYPE_INFO))
.finish()
)
}

}

你可能感兴趣的:(随机,flink)