gpt4 book ai didi

java - SQL Server 的 DBCPConnectionPool Controller 服务,jdbc 异常

转载 作者:搜寻专家 更新时间:2023-11-01 03:17:41 27 4
gpt4 key购买 nike

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

后台线程是here .

我创建了一个指向 SQL Server 数据库的 DBCPConnectionPool Controller 服务,我能够从表中获取数据并将其写入本地磁盘(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;
}

enter image description here

当我将池用作自定义处理器中的属性时,挑战就出现了。在处理器的代码中,我需要调用数据库中的一个函数,但这会导致一个指向 JDBC 驱动程序的 SQLException。请注意,相同的驱动程序在独立的 Java 代码中正常运行(在后台线程中提供以避免使这篇文章困惑)并且我从函数中获取返回值。我怀疑 Controller 服务配置不正确——它可以执行选择查询,但是当代码调用函数时,它会抛出异常。我错过了什么?

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

最佳答案

“java.sql.SQLFeatureNotSupportedException:registerOutParameter 未实现”您的代码正在使用驱动程序中不可用的功能。

具体来说,根据堆栈跟踪,您的驱动程序正在调用 JDBC 4.2 (Java 8) 中引入的 registerOutParameter(int parameterIndex, SQLType sqlType)。此方法在 java.sql.CallableStatement 接口(interface)中具有以下默认实现:

default void registerOutParameter(int parameterIndex, SQLType sqlType)
throws SQLException {
throw new SQLFeatureNotSupportedException("registerOutParameter not implemented");
}

throwjava.sql.CallableStatement 中的第 2613 行,与堆栈跟踪匹配。

作为this method is implemented在最新版本的 Microsoft SQL Server JDBC 驱动程序中,您使用的是旧版本,或者驱动程序的对象包装在不支持 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)

关于java - SQL Server 的 DBCPConnectionPool Controller 服务,jdbc 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42854840/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com