DBCPConnectionPool用于SQL Server的控制器服务,jdbcexception

在Windows 7和RHEL 7上测试了NiFi 1.1.1。

后台主题​​就在这里 。

我创建了一个指向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代码中正常运行 (在后台线程中提供,以避免混乱此post),并从函数中获取返回值。 我怀疑Controller Service配置不正确 – 它可以执行select查询但是当代码调用一个函数时,它会抛出exception。 我错过了什么?

 Process or SQL exception in  2017-03-17 09:25:30,717 ERROR [Timer-Driven Process Thread-6] csdprocessors.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 

“java.sql.SQLFeatureNotSupportedException:registerOutParameter not implemented”您的代码使用的是驱动程序中未提供的function。

具体来说,基于registerOutParameter(int parameterIndex, SQLType sqlType) ,您的驱动程序正在调用JDBC 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"); } 

其中throwjava.sql.CallableStatement第2613行,它与stacktrace匹配。

由于此方法在最新版本的Microsoft SQL Server JDBC驱动程序中实现的,因此您使用的是旧版本,或者驱动程序的对象包含在不支持JDBC 4.2的代理中。

我建议你升级到最新版本的驱动程序 ,目前是v6.1.0。 由于你的另一个问题建议你使用maven,那么你应该确保驱动程序的 Maven坐标(他们在开源驱动程序时更改了它):

  com.microsoft.sqlserver mssql-jdbc 6.1.0.jre8  

如果问题仍然存在,那么由于com.datalake.processors.SQLServerCDCProcessor是您自己的代码(如您的其他问题所示),您应该将其更改为不调用registerOutParameter(int parameterIndex, SQLType sqlType) ,但是旧的registerOutParameter(int parameterIndex, int sqlType)