问题描述
使用 FlinkSql 的 jdbc 连接器 读取 mysql 的一张表,总是提示
Exception in thread "main" org.apache.flink.table.api.ValidationException: Unable to create a source for reading table 'default_catalog.default_database
程序代码
public static void main(String[] args) { StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); env.setParallelism(4); StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env); tableEnv.executeSql("CREATE TABLE dim_dic (\n" + " dic_id STRING,\n" + " dic_desc STRING,\n" + " update_time STRING,\n" + " PRIMARY KEY (dic_id) NOT ENFORCED \n" + ") WITH (\n" + " 'connector' = 'jdbc',\n" + " 'url' = 'jdbc:mysql://hostname:3306/db',\n" + " 'table-name' = 'dim_dic',\n" + " 'username' = 'username',\n" + " 'password' = 'pwd----'\n" + ")"); tableEnv.executeSql("select * from dim_dic ").print(); }
解决方式
仔细看了下SQL无误,再次查看官网发现少了依赖
<!-- https://mvnrepository.com/artifact/org.apache.flink/flink-connector-jdbc --> <dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-connector-jdbc</artifactId> <version>3.1.1-1.17</version> <scope>provided</scope> </dependency>
标签:jdbc,database,default,FlinkSQL,dic,Unable,table,create From: https://www.cnblogs.com/wdh01/p/18113052