在Windows 7和RHEL 7上测试了NiFi 1.1.1。
后台主题是here。
我创建了一个指向SQL Server数据库的DBCPConnectionPool控制器服务,我能够从表中获取数据并将其写入本地磁盘(ExecuteSQL - > ConvertAvroToJSON - > PutFile)。
我的代码:
public byte[] getMaxLSN(Connection connection, String containerDB) {
String dbMaxLSN = "{? = CALL sys.fn_cdc_get_max_lsn()}";
byte[] maxLSN = null;
try (final CallableStatement cstmt = connection.prepareCall(dbMaxLSN);) {
cstmt.registerOutParameter(1, java.sql.JDBCType.BINARY);
cstmt.execute();
if (cstmt.getBytes(1) == null || cstmt.getBytes(1).length <= 0) {
System.out.println("Coudln't retrieve the max lsn for the db "
+ containerDB);
} else {
maxLSN = cstmt.getBytes(1);
}
} catch (SQLException sqlException) {
System.out.println("sqlException !!!");
sqlException.printStackTrace();
}
return maxLSN;
}
当我在自定义处理器中将池用作属性时,出现了挑战。在处理器的代码中,我需要在db中调用一个函数,但这会导致指向JDBC驱动程序的 SQLException。请注意,相同的驱动程序在独立的Java代码中正常运行(在后台线程中提供,以避免混乱此帖子)并从函数中获取返回值。我怀疑控制器服务配置不正确 - 它可以执行选择查询,但是当代码调用函数时,它会抛出异常。我错过了什么?
Process or SQL exception in <configure logger template to pick the code location>
2017-03-17 09:25:30,717 ERROR [Timer-Driven Process Thread-6] c.s.d.processors.SQLServerCDCProcessor
org.apache.nifi.processor.exception.ProcessException: Coudln't retrieve the max lsn for the db test
at com.datalake.processors.SQLServerCDCProcessor$SQLServerCDCUtils.getMaxLSN(SQLServerCDCProcessor.java:692) ~[nifi-NiFiCDCPoC-processors-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
at com.datalake.processors.SQLServerCDCProcessor.getChangedTableQueries(SQLServerCDCProcessor.java:602) ~[nifi-NiFiCDCPoC-processors-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
at com.datalake.processors.SQLServerCDCProcessor.onTrigger(SQLServerCDCProcessor.java:249) ~[nifi-NiFiCDCPoC-processors-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
at org.apache.nifi.processor.AbstractProcessor.onTrigger(AbstractProcessor.java:27) [nifi-api-1.1.1.jar:1.1.1]
at org.apache.nifi.controller.StandardProcessorNode.onTrigger(StandardProcessorNode.java:1099) [nifi-framework-core-1.1.1.jar:1.1.1]
at org.apache.nifi.controller.tasks.ContinuallyRunProcessorTask.call(ContinuallyRunProcessorTask.java:136) [nifi-framework-core-1.1.1.jar:1.1.1]
at org.apache.nifi.controller.tasks.ContinuallyRunProcessorTask.call(ContinuallyRunProcessorTask.java:47) [nifi-framework-core-1.1.1.jar:1.1.1]
at org.apache.nifi.controller.scheduling.TimerDrivenSchedulingAgent$1.run(TimerDrivenSchedulingAgent.java:132) [nifi-framework-core-1.1.1.jar:1.1.1]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_71]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [na:1.8.0_71]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_71]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_71]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_71]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_71]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_71]
Caused by: java.sql.SQLFeatureNotSupportedException: registerOutParameter not implemented
at java.sql.CallableStatement.registerOutParameter(CallableStatement.java:2613) ~[na:1.8.0_71]
at com.datalake.processors.SQLServerCDCProcessor$SQLServerCDCUtils.getMaxLSN(SQLServerCDCProcessor.java:677) ~[nifi-NiFiCDCPoC-processors-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
... 14 common frames omitted
答案 0 :(得分:2)
“java.sql.SQLFeatureNotSupportedException:registerOutParameter not implemented”您的代码使用的是驱动程序中没有的功能。
具体来说,基于堆栈跟踪,您的驱动程序正在调用{4.2}(Java 8)中引入的registerOutParameter(int parameterIndex, SQLType sqlType)
。此方法在java.sql.CallableStatement
接口中具有以下默认实现:
default void registerOutParameter(int parameterIndex, SQLType sqlType)
throws SQLException {
throw new SQLFeatureNotSupportedException("registerOutParameter not implemented");
}
throw
在java.sql.CallableStatement
中与第2613行匹配,与堆栈跟踪匹配。
作为最新版本的Microsoft SQL Server JDBC驱动程序中的this method is implemented,您使用的是旧版本,或者驱动程序的对象包含在不支持JDBC 4.2的代理中。
我建议您升级到latest version of the driver,目前为v6.1.0。由于another question of yours建议您使用maven,因此您应该确保驱动程序的新 Maven坐标(他们在开源驱动程序时更改了它):
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>
如果问题仍然存在,那么由于com.datalake.processors.SQLServerCDCProcessor
是您自己的代码(如other question所示),您应该将其更改为不调用registerOutParameter(int parameterIndex, SQLType sqlType)
,而是更早registerOutParameter(int parameterIndex, int sqlType)
1}}。