使用 JDBC 创建与 Oracle DB 的 apache Spark 连接

问题描述 投票:0回答:1

我正在尝试使用 Apache Spark 和 scala 创建到我公司的 Oracle 测试服务器的连接。以下是我在 Spark-Shell 中运行的语句。我使用的是JDK 8,并在spark的jar目录中安装了适当的jdbc驱动程序。

我的网址或其他配置的语法看起来不正确吗?

底部的错误消息是否意味着比“网络适配器无法建立连接”更有用的信息?

scala> val user = <"username">
scala> val password = <"password">

val jdbc = spark.read.format("jdbc").option("url","jdbc:oracle:thin:@(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST =<hostname>)(PORT = 1521))(LOAD_BALANCE = YES)(FAILOVER = YES)(SERVER = DEDICATED)(CONNECT_DATA = (SERVICE_NAME = <service name>)(FAILOVER_MODE =(TYPE = SELECT)(METHOD = BASIC)(RETRIES = 180)(DELAY = 5))))").option("driver", "oracle.jdbc.driver.OracleDriver").option("query","select * from realmed.office_user_status_type").option("user",username).option("password",password).load()

当上面的命令执行时,看起来它正在尝试连接一分钟左右,然后返回以下错误

java.sql.SQLRecoverableException: ORA-17820: The network adapter could not establish the connection. (CONNECTION_ID=QDew7TDmTtecLW0yGr39SA==)
https://docs.oracle.com/error-help/db/ora-17820/
  at oracle.jdbc.driver.T4CConnection.handleLogonNetException(T4CConnection.java:1382)
  at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:975)
  at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:1126)
  at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:104)
  at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:825)
  at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:651)
  at org.apache.spark.sql.execution.datasources.jdbc.connection.BasicConnectionProvider.getConnection(BasicConnectionProvider.scala:49)
  at org.apache.spark.sql.execution.datasources.jdbc.connection.ConnectionProviderBase.create(ConnectionProvider.scala:102)
  at org.apache.spark.sql.jdbc.JdbcDialect.$anonfun$createConnectionFactory$1(JdbcDialects.scala:160)
  at org.apache.spark.sql.jdbc.JdbcDialect.$anonfun$createConnectionFactory$1$adapted(JdbcDialects.scala:156)
  at org.apache.spark.sql.execution.datasources.jdbc.JDBCRDD$.getQueryOutputSchema(JDBCRDD.scala:63)
  at org.apache.spark.sql.execution.datasources.jdbc.JDBCRDD$.resolveTable(JDBCRDD.scala:58)
  at org.apache.spark.sql.execution.datasources.jdbc.JDBCRelation$.getSchema(JDBCRelation.scala:241)
  at org.apache.spark.sql.execution.datasources.jdbc.JdbcRelationProvider.createRelation(JdbcRelationProvider.scala:37)
  at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:346)
  at org.apache.spark.sql.DataFrameReader.loadV1Source(DataFrameReader.scala:229)
  at org.apache.spark.sql.DataFrameReader.$anonfun$load$2(DataFrameReader.scala:211)
  at scala.Option.getOrElse(Option.scala:201)
  at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:211)
  at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:172)
  ... 42 elided
Caused by: oracle.net.ns.NetException: ORA-17820: The network adapter could not establish the connection. (CONNECTION_ID=QDew7TDmTtecLW0yGr39SA==)
https://docs.oracle.com/error-help/db/ora-17820/
  at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:769)
  at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:707)
  at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:938)
  at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:911)
  at oracle.net.ns.NSProtocolNIO.redirectConnection(NSProtocolNIO.java:525)
  at oracle.net.ns.NSProtocolNIO.handleConnectPacketResponse(NSProtocolNIO.java:447)
  at oracle.net.ns.NSProtocolNIO.negotiateConnection(NSProtocolNIO.java:268)
  at oracle.net.ns.NSProtocol.connect(NSProtocol.java:331)
  at oracle.jdbc.driver.T4CConnection.connectNetworkSessionProtocol(T4CConnection.java:2947)
  at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:910)
  ... 60 more

java oracle scala apache-spark jdbc
1个回答
0
投票

我找到了一个在语法上有效的网址版本。这是我的主要障碍。但是,我遇到了无效的用户名/密码,但这是另一个问题。

("url","jdbc:oracle:thin:@//<host name>:1521/<service name>").
© www.soinside.com 2019 - 2024. All rights reserved.