Java SQL Server的DBCPConnectionPool控制器服务,jdbc异常

Java SQL Server的DBCPConnectionPool控制器服务,jdbc异常,java,jdbc,apache-nifi,Java,Jdbc,Apache Nifi,NiFi 1.1.1在Windows 7和RHEL 7上都进行了测试 背景线程是 我已经创建了一个指向SQL Server db的DBCPConnectionPool控制器服务,我能够从表中获取数据并将其写入本地磁盘(ExecuteSQL->ConvertAvroToJSON->PutFile) 我的代码: public byte[] getMaxLSN(Connection connection, String containerDB) { String dbMaxLSN = "{?

NiFi 1.1.1在Windows 7和RHEL 7上都进行了测试

背景线程是

我已经创建了一个指向SQL Server db的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;
}
public byte[]getMaxLSN(连接,字符串containerDB){
字符串dbMaxLSN=“{?=CALL sys.fn\u cdc\u get\u max\u lsn()}”;
字节[]maxLSN=null;
try(final CallableStatement cstmt=connection.prepareCall(dbMaxLSN);){
registerOutParameter(1,java.sql.JDBCType.BINARY);
cstmt.execute();
如果(cstmt.getBytes(1)==null | | cstmt.getBytes(1).length“java.sql.SQLFeatureNotSupportedException:registerOutParameter未实现”,则代码使用的是驱动程序中不可用的功能

具体地说,基于stacktrace,您的驱动程序正在调用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");
}
其中,
throw
java.sql.CallableStatement
中的第2613行,它与stacktrace匹配

与最新版本的Microsoft SQL Server JDBC驱动程序一样,您使用的不是旧版本,就是驱动程序的对象包装在不支持JDBC 4.2的代理中

我建议您升级到当前的v6.1.0。正如建议您使用maven一样,您应该确保驱动程序的maven坐标(他们在开源驱动程序时更改了坐标):


com.microsoft.sqlserver
),您只需将其更改为不调用
registerOutParameter(int-parameterIndex,SQLType SQLType)
,而是调用较旧的
registerOutParameter(int-parameterIndex,int-SQLType)

default void registerOutParameter(int parameterIndex, SQLType sqlType)
    throws SQLException {
    throw new SQLFeatureNotSupportedException("registerOutParameter not implemented");
}
<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>mssql-jdbc</artifactId>
    <version>6.1.0.jre8</version>
</dependency>