Search code examples
javalogstashlogstash-jdbc

IllegalAccessError when using logstash jcdc output


I have a simple logstash configuration:

input {
      jdbc {
      jdbc_driver_library => "..\sqljdbc_6.0\enu\jre8\sqljdbc42.jar"
      jdbc_connection_string => "jdbc:sqlserver:/server:1433;databaseName=DBNAME;integratedSecurity=true;"
      jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
      statement => "select top(10) eventdata from TABLE"       
        schedule => "*/20 * * * * *"
           }
    }

    output {
        jdbc {
            connection_string  => "jdbc:sqlserver://DBSERVER:1433;databaseName=DBNAME;integratedSecurity=true;"
            driver_jar_path  =>"..\sqljdbc_6.0\enu\jre8\sqljdbc42.jar"
            statement => ["insert into TABLENAME(t) values(?)", "@timestamp"]
      }  
    }

The input part works fine reading values from the db. However, when it tries to output into another database, I receive the following error:

 Java::JavaLang::IllegalAccessError: com/microsoft/sqlserver/jdbc/StreamError
  2076       com.microsoft.sqlserver.jdbc.TDSTokenHandler.onError(com/microsoft/sqlserver/jdbc/tdsparser.java:222)
  2076       com.microsoft.sqlserver.jdbc.TDSParser.parse(com/microsoft/sqlserver/jdbc/tdsparser.java:83)

I'm using logstash 6.5, sqljdbc 4.2 and OpenJDK (Amazon Corretto 8.2 JRE)

When I change the output config to output to a file or console it works fine.

Any help will be appreciated.


Solution

  • I've found a solution to this problem and posting it here in case anyone faces a similar issue.

    The logstash_jdbc_output plugin has been installed to logstash using Oracle JDK. Later on, Oracle JDK has been replaced with Open JDK which was the cause of the problem. The solution was to re-install the plugin using Open JDK.