Java :: JavaSql :: SQLException:侦听器拒绝连接并出现以下错误

时间:2018-06-07 17:46:50

标签: java oracle elasticsearch jdbc logstash

执行logstash JDBC配置文件,执行文件时遇到以下错误

Error: Java::JavaSql::SQLException: Listener refused the connection with the following error: ORA-12505, TNS:listener does not currently know of SID given in connect descriptor The Connection descriptor used by the client was: localhost:1521:xe

请找到我的logstash配置文件:

input {
  jdbc {
    jdbc_driver_library => "D:\1SearchEngine\data\ojdbc14.jar"
    jdbc_driver_class => "Java::oracle.jdbc.OracleDriver"
    jdbc_connection_string => "jdbc:oracle:thin:@localhost:1521:xe"
    jdbc_user => "ub"
    jdbc_password => "1234567"
    statement => "select * from documents"
  }
}

output {
  elasticsearch {
    hosts => ["localhost:9200"]
    index => "documents"
  }
}

但是我能够通过SQLDeveloper连接数据库而没有任何问题。

1 个答案:

答案 0 :(得分:0)

在sqldev中,您可以获得正在使用的jdbc url。是show jdbc在工作表中(或在sqlcl中)。您可以确保在logstash设置中以相同的方式连接。

这是一个例子。请参阅Driver URL行。

另请更新该驱动程序。 ojdbc8.jar是最新的,可从http://www.oracle.com/technetwork/database/application-development/jdbc/downloads/index.html

下载
SQL> show jdbc
-- Database Info --
Database Product Name: Oracle
Database Product Version: Oracle Database 12c Standard Edition Release 12.1.0.2.0 - 64bit Production
Database Major Version: 12
Database Minor Version: 1
-- Driver Info --
Driver Name: Oracle JDBC driver
Driver Version: 12.2.0.1.0
Driver Major Version: 12
Driver Minor Version: 2
Driver URL: jdbc:oracle:thin:@127.0.0.1:1521:xe
Driver Location: 
resource: oracle/jdbc/OracleDriver.class
jar: /Users/klrice/workspace_commons/dbtools-commons/sqlcl/target/dbtools-sqlcl-18.1.0-SNAPSHOT-sqlcl/dbtools-sqlcl-18.1.0-SNAPSHOT/lib/ojdbc8.jar  
JarSize: 4036257  
JarDate: Thu Jan 25 14:31:44 EST 2018  
resourceSize: 2604  
resourceDate: Tue Dec 13 08:39:48 EST 2016

SQL>