srv
srv

Reputation: 113

AWS Glue: How to connect oracle db using JDBC

When I'm trying to connect to external Oracle DB from AWS Glue using JDBC getting below errors. Could some one help on this issue?

Driver code using is below:

test_df = spark.read.format('jdbc').options(url='jdbc:oracle:thin:username/password@//myhostname:1521/servicename',     dbtable="test", driver='oracle.jdbc.driver.OracleDriver').load()

Errors logs are below:

py4j.protocol.Py4JJavaError: An error occurred while calling o65.load.
: java.sql.SQLRecoverableException: IO Error: Unknown host specified at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:743)
at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:666)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:566)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:280)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:214)
at java.lang.Thread.run(Thread.java:748)

Thanks, Srini

Upvotes: 1

Views: 3526

Answers (1)

Romeo Ninov
Romeo Ninov

Reputation: 7265

It seems like you can't resolve the hostname you specify in to the command. Check this line:

: java.sql.SQLRecoverableException: IO Error:Unknown hostspecified at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:743)

You can use nslookup or dig command to check if the hostname is resolved like:

nslookup hostname

dig hostname

If you do not get IP as answer please correct you hostname, /etc/hosts record or DNS record

All those tests and updates need to be run on the host where your code is running!

Edit1: If you do not have control on the host where your code is running you can:

  1. use FQDN of your host
  2. Use IP address instead of hostname (very bad advise, use it as temporary workaround)

Upvotes: 1

Related Questions