Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Flink example-read database

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Private final static Logger logger = LoggerFactory.getLogger (GetData.class); public static void main (String [] arg) throws Exception {TypeInformation [] fieldTypes = new TypeInformation [] {BasicTypeInfo.STRING_TYPE_INFO}; RowTypeInfo rowTypeInfo = new RowTypeInfo (fieldTypes) JDBCInputFormat jdbcInputFormat = JDBCInputFormat.buildJDBCInputFormat () .setDrivername ("com.mysql.jdbc.Driver") .setDBUrl ("jdbc:mysql://ip:3306/tablename?characterEncoding=utf8") .setUsername ("*") .setPassword ("*") .setQuery ("select name from words") .setRowTypeInfo (rowTypeInfo) ). Please () Final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment (); DataSource s = env.createInput (jdbcInputFormat); / / datasource BatchTableEnvironment tableEnv = new BatchTableEnvironment (env, TableConfig.DEFAULT ()); tableEnv.registerDataSet ("T2", s); tableEnv.sqlQuery ("select * from T2"). PrintSchema (); Table query = tableEnv.sqlQuery ("select * from T2"); DataSet result = tableEnv.toDataSet (query, Row.class); result.print (); System.out.println (s.count ());}

Type the required classes into a jar through the plug-in

Maven-assembly-plugin false jar-with-dependencies * Make-assembly package Assembly

And then execute

. / bin/flink run / flink-1.8.0/collector-api-0.1.jar

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report