解决flink读取TDEngine的数据Could not initialize class com.taosdata.jdbc.TSDBJNIConnector
需要用flink读取TDEngine的数据,用jdbc方式连接,运行报错:Could not initialize class com.taosdata.jdbc.TSDBJNIConnector
JDBC-JNI的方式需要 TDengine-client(使用JDBC-JNI时必须,使用JDBC-RESTful时非必须),所以采用JDBC-RESTful 的方式,原因是一开始想用
JDBC-JNI 的方式,想改用 JDBC-RESTful 代码没改干净。
通过指定URL获取连接,如下所示:
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
String jdbcUrl = "jdbc:TAOS-RS://taosdemo.com:6041/test?user=root&password=taosdata";
Connection conn = DriverManager.getConnection(jdbcUrl);
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
String jdbcUrl = "jdbc:TAOS-RS://taosdemo.com:6041/test?user=root&password=taosdata";
Connection conn = DriverManager.getConnection(jdbcUrl);
以上示例,使用 JDBC-RESTful 的 driver,建立了到 hostname 为 taosdemo.com,端口为 6041,数据库名为 test 的连接。这个 URL 中指定用户名(user)为 root,密码(password)为 taosdata。
使用 JDBC-RESTful 接口,不需要依赖本地函数库。与 JDBC-JNI 相比,仅需要:
- driverClass 指定为“com.taosdata.jdbc.rs.RestfulDriver”;
- jdbcUrl 以“jdbc:TAOS-RS://”开头;
- 使用 6041 作为连接端口。
按上面的方式修改,果然没有再报上面的错误。