Filip
Filip

Reputation: 1058

Logstash Oracle Driver issue

I am trying to setup simple Logstash 7.6.0 pipeline with a JDBC input plugin that connects to an Oracle DB.

Whatever I am trying, I always get the same error :

  2052     LogStash::PluginLoadingError
  2052     oracle.jdbc.OracleDriver not loaded. Are you sure you've included the correct jdbc driver in :jdbc_driver_library?
  2052       C:/Apps/logstash/logstash-7.6.0/vendor/bundle/jruby/2.5.0/gems/logstash-integration-jdbc-5.0.0/lib/logstash/plugin_mixins/jdbc/jdbc.rb:179:in `open_jdbc_connection'
  2052       C:/Apps/logstash/logstash-7.6.0/vendor/bundle/jruby/2.5.0/gems/logstash-integration-jdbc-5.0.0/lib/logstash/plugin_mixins/jdbc/jdbc.rb:242:in `execute_statement'

This seems to affect ONLY the Oracle driver. I have tried using H2 (details below), PostgreSQL. It works.

I am running logstash in a Docker image, so I tried locally, and I get the exact same result.

I am running out of options.

Some details :

Here's my config for Oracle

input {
  jdbc {

    schedule => "*/5 * * * * *"

    jdbc_connection_string => "jdbc:oracle:thin:@host:1521/service_name"
    jdbc_driver_library => "C:/Apps/ORACLE_DRIVER/ojdbc7.jar"
    jdbc_driver_class => "oracle.jdbc.OracleDriver"
    statement => "SELECT p.* FROM  person p "
    jdbc_user => "x"
    jdbc_password => "y"

  }
}

output {
  stdout {
    codec => rubydebug
  }

}

I initially got the driver from my local maven ".m2" repository, so just to make sure I re-downloaded the driver from : https://download.oracle.com/otn/utilities_drivers/jdbc/121010/ojdbc7.jar

If I misspel the "jdbc_driver_library", I get a different error, so I know my path is good

I have looked inside the jar, and I can see the driver :

enter image description here

I created this simple java class to test the driver / connection string, and it works just fine :

package oracle;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Date;

public class TestConnection {
    public static void main(String[] args) {

        try {
            Class.forName("oracle.jdbc.OracleDriver");
            Connection con = DriverManager.getConnection("jdbc:oracle:thin:@host:1521/service_name", "x", "y");
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT p.* FROM person p");
            while (rs.next()) {                
                System.out.println(rs.getString(1) + " : " + rs.getString(2));
            }
            System.out.println(new Date());
            con.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

So I went on, and tried with a sample H2 database, and it worked flawlessly on the first attemp, here's the config that works (with a H2 tcp server running). Almost identical to Oracle config

input {
  jdbc {

    schedule => "*/5 * * * * *"

    jdbc_connection_string => "jdbc:h2:tcp://localhost/~/test"
    jdbc_driver_library => "C:/Apps/h2/h2.jar"
    jdbc_driver_class => "org.h2.Driver"
    statement => "SELECT p.* FROM public.person p"
    jdbc_user => "sa"
    jdbc_password => ""

  }
}

output {
  stdout {
    codec => rubydebug
  }

}

I have tried to add logs in the "logstash/config/log4j2.properties"

logger.jdbcinput.name = logstash.inputs.jdbc
logger.jdbcinput.level = DEBUG

But I got nothing more.

I am out of inspiration.

Any idea?

Thanks

Upvotes: 0

Views: 1914

Answers (1)

Filip
Filip

Reputation: 1058

I finally found the answer here : https://github.com/logstash-plugins/logstash-input-jdbc/issues/43

jdbc_driver_class => "oracle.jdbc.OracleDriver"

needs to be :

jdbc_driver_class => "Java::oracle.jdbc.OracleDriver

Why add this Java:: prefix? Why does it work with other drivers without it? I don't understand.

Upvotes: 2

Related Questions