<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to connect via JDBC to SAP-HANA in a Databricks Notebook? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-connect-via-jdbc-to-sap-hana-in-a-databricks-notebook/m-p/104434#M41745</link>
    <description>&lt;P&gt;I have a set of connection credentials for SAP-HANA, how can I retrieve data from that location using JDBC?&lt;/P&gt;&lt;P&gt;I have already installed in my cluster the ngdbc.jar (for the driver), but this simple Query has already taken more than 5 minutes and I don't know if it is doing something or not. The HOST was already added to the network routing tables for reaching the HOST.&lt;/P&gt;&lt;P&gt;EDIT: It failed by &lt;U&gt;timeout&lt;/U&gt;.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Py4JJavaError: An error occurred while calling o578.load.
: com.sap.db.jdbc.exceptions.JDBCDriverException: SAP DBTech JDBC: Cannot connect to jdbc:sap://[REDACTED]:30013/ [Cannot connect to host [REDACTED]:30013 [Connection timed out], -813.].&lt;/LI-CODE&gt;&lt;P&gt;The Script:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# datos de input
query = "SELECT COUNT(*) FROM MY_TABLE"

# SQL connection string
jdbcHostname = dbutils.secrets.get(scope="my_kv", key="host")
jdbcPort = 30013
jdbcDatabase = "MY_DATABASE"
jdbcUrl = f"jdbc:sap://{jdbcHostname}:{jdbcPort}/?databaseName={jdbcDatabase}"
jdbcUsername = dbutils.secrets.get(scope="my_kv", key="user")
jdbcPassword = dbutils.secrets.get(scope="my_kv", key="password")

attempts = 0
max_attempts = 3

while attempts &amp;lt; max_attempts:
    try:
        df_input_data = (
            spark.read.format("jdbc")
            .option("driver", "com.sap.db.jdbc.Driver")
            .option("url", jdbcUrl)
            .option("user", jdbcUsername)
            .option("password", jdbcPassword)
            .option("query", query)
            .option("timeout", "5")
            .option("fetchsize", "1000")
            .load()
        )
        display(df_input_data)
        break
    except Exception as e:
        attempts += 1
        if attempts == max_attempts:
            raise e&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jan 2025 21:07:29 GMT</pubDate>
    <dc:creator>PabloCSD</dc:creator>
    <dc:date>2025-01-06T21:07:29Z</dc:date>
    <item>
      <title>How to connect via JDBC to SAP-HANA in a Databricks Notebook?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-connect-via-jdbc-to-sap-hana-in-a-databricks-notebook/m-p/104434#M41745</link>
      <description>&lt;P&gt;I have a set of connection credentials for SAP-HANA, how can I retrieve data from that location using JDBC?&lt;/P&gt;&lt;P&gt;I have already installed in my cluster the ngdbc.jar (for the driver), but this simple Query has already taken more than 5 minutes and I don't know if it is doing something or not. The HOST was already added to the network routing tables for reaching the HOST.&lt;/P&gt;&lt;P&gt;EDIT: It failed by &lt;U&gt;timeout&lt;/U&gt;.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Py4JJavaError: An error occurred while calling o578.load.
: com.sap.db.jdbc.exceptions.JDBCDriverException: SAP DBTech JDBC: Cannot connect to jdbc:sap://[REDACTED]:30013/ [Cannot connect to host [REDACTED]:30013 [Connection timed out], -813.].&lt;/LI-CODE&gt;&lt;P&gt;The Script:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# datos de input
query = "SELECT COUNT(*) FROM MY_TABLE"

# SQL connection string
jdbcHostname = dbutils.secrets.get(scope="my_kv", key="host")
jdbcPort = 30013
jdbcDatabase = "MY_DATABASE"
jdbcUrl = f"jdbc:sap://{jdbcHostname}:{jdbcPort}/?databaseName={jdbcDatabase}"
jdbcUsername = dbutils.secrets.get(scope="my_kv", key="user")
jdbcPassword = dbutils.secrets.get(scope="my_kv", key="password")

attempts = 0
max_attempts = 3

while attempts &amp;lt; max_attempts:
    try:
        df_input_data = (
            spark.read.format("jdbc")
            .option("driver", "com.sap.db.jdbc.Driver")
            .option("url", jdbcUrl)
            .option("user", jdbcUsername)
            .option("password", jdbcPassword)
            .option("query", query)
            .option("timeout", "5")
            .option("fetchsize", "1000")
            .load()
        )
        display(df_input_data)
        break
    except Exception as e:
        attempts += 1
        if attempts == max_attempts:
            raise e&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2025 21:07:29 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-connect-via-jdbc-to-sap-hana-in-a-databricks-notebook/m-p/104434#M41745</guid>
      <dc:creator>PabloCSD</dc:creator>
      <dc:date>2025-01-06T21:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to connect via JDBC to SAP-HANA in a Databricks Notebook?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-connect-via-jdbc-to-sap-hana-in-a-databricks-notebook/m-p/104437#M41747</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/106298"&gt;@PabloCSD&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;Can you run this command?&lt;/P&gt;
&lt;P&gt;nc -zv &amp;lt;hostname&amp;gt; &amp;lt;port&amp;gt;&lt;/P&gt;
&lt;P&gt;Also do a telnet just to confirm the connectivity.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Adding this articule:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.databricks.com/blog/fastest-way-access-sap-hana-data-databricks-using-sap-sparkjdbc" target="_blank"&gt;https://www.databricks.com/blog/fastest-way-access-sap-hana-data-databricks-using-sap-sparkjdbc&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2025 22:03:09 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-connect-via-jdbc-to-sap-hana-in-a-databricks-notebook/m-p/104437#M41747</guid>
      <dc:creator>Alberto_Umana</dc:creator>
      <dc:date>2025-01-06T22:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to connect via JDBC to SAP-HANA in a Databricks Notebook?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-connect-via-jdbc-to-sap-hana-in-a-databricks-notebook/m-p/104520#M41780</link>
      <description>&lt;P&gt;Hello there &lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/106294"&gt;@Alberto_Umana&lt;/a&gt; ,&lt;/P&gt;&lt;P&gt;After the architecture team asociated the subnet, when I run the command:&lt;/P&gt;&lt;P&gt;&lt;U&gt;nc&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;!nc -zv 172.XY.ZKL.MN 30013

[REDACTED]: inverse host lookup failed: Unknown host
(UNKNOWN) [[REDACTED]] 30013 (?) open&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;ping&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;!ping -c 4 172.XY.ZKL.MN

PING [REDACTED] ([REDACTED]) 56(84) bytes of data.
64 bytes from [REDACTED]: icmp_seq=1 ttl=57 time=138 ms
64 bytes from [REDACTED]: icmp_seq=2 ttl=57 time=130 ms
64 bytes from [REDACTED]: icmp_seq=3 ttl=57 time=127 ms
64 bytes from [REDACTED]: icmp_seq=4 ttl=57 time=127 ms

--- [REDACTED] ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3000ms
rtt min/avg/max/mdev = 126.922/130.489/137.854/4.449 ms&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;telnet&lt;/U&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;telnet 172.XY.ZKL.MN 30013

Trying [REDACTED]...
Connected to [REDACTED].
Escape character is '^]'.
Connection closed by foreign host.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Even though the connection is ok, the query is not working by authentication:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;df_my_table = (spark.read
 .format("jdbc")
 .option("driver","com.sap.db.jdbc.Driver")
 .option("url", f'jdbc:sap://{jdbcHostname}:30013/?autocommit=false')
 .option("dbtable", "MY_TABLE")
 .option("user", jdbcUsername)  ## should be using databricks secrets instead of putting credentials in code
 .option("password", jdbcPassword)  ## should be using databricks secrets instead of putting credentials in code
 .load()
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Py4JJavaError: An error occurred while calling o1040.load.
: com.sap.db.jdbc.exceptions.jdbc40.SQLInvalidAuthorizationSpecException: [10]: authentication failed
	at com.sap.db.jdbc.exceptions.jdbc40.SQLInvalidAuthorizationSpecException.createException(SQLInvalidAuthorizationSp&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was following the url that you provided me&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2025 14:44:11 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-connect-via-jdbc-to-sap-hana-in-a-databricks-notebook/m-p/104520#M41780</guid>
      <dc:creator>PabloCSD</dc:creator>
      <dc:date>2025-01-07T14:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to connect via JDBC to SAP-HANA in a Databricks Notebook?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-connect-via-jdbc-to-sap-hana-in-a-databricks-notebook/m-p/104535#M41784</link>
      <description>&lt;P&gt;Added the database parameter:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;df_sap_hana_table = (spark.read
 .format("jdbc")
 .option("driver", "com.sap.db.jdbc.Driver")
 .option("url", f'jdbc:sap://{jdbcHostname}:{jdbcPort}/?databaseName={jdbcDatabase}')
 .option("query", "SELECT 1 FROM DUMMY")
 .option("user", jdbcUsername)
 .option("password", jdbcPassword)
 .load()
)&lt;/LI-CODE&gt;&lt;P&gt;Still getting the timeout error:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Py4JJavaError: An error occurred while calling o1100.load.
: com.sap.db.jdbc.exceptions.JDBCDriverException: SAP DBTech JDBC: Cannot connect to jdbc:sap://[REDACTED]:30013/ [Cannot connect to host 172.XY.ZKL.MN:30041 [Connection timed out], -813.].&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2025 14:59:37 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-connect-via-jdbc-to-sap-hana-in-a-databricks-notebook/m-p/104535#M41784</guid>
      <dc:creator>PabloCSD</dc:creator>
      <dc:date>2025-01-07T14:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to connect via JDBC to SAP-HANA in a Databricks Notebook?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-connect-via-jdbc-to-sap-hana-in-a-databricks-notebook/m-p/104576#M41801</link>
      <description>&lt;P&gt;It worked changing the port to: &lt;STRONG&gt;30041&lt;/STRONG&gt;, the port for the next tenant (reference: &lt;A title="HANA connectivity and ports" href="https://community.sap.com/t5/technology-q-a/hana-connectivity-and-ports/qaq-p/12193927" target="_blank" rel="noopener"&gt;https://community.sap.com/t5/technology-q-a/hana-connectivity-and-ports/qaq-p/12193927&lt;/A&gt; ).&lt;/P&gt;&lt;LI-CODE lang="python"&gt;jdbcQuery = '(SELECT * FROM DUMMY)'

df_sap_hana_dummy_table = (spark.read
 .format("jdbc")
 .option("driver", "com.sap.db.jdbc.Driver")
 .option("url", f"jdbc:sap://{jdbcHostname}:30041/?databaseName={jdbcDatabase}")
 .option("dbtable", jdbcQuery)
 .option("user", jdbcUsername)
 .option("password", jdbcPassword)
 .load()
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2025 16:52:57 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-connect-via-jdbc-to-sap-hana-in-a-databricks-notebook/m-p/104576#M41801</guid>
      <dc:creator>PabloCSD</dc:creator>
      <dc:date>2025-01-07T16:52:57Z</dc:date>
    </item>
  </channel>
</rss>

