簡體   English   中英

無法使用火花 scala 連接到 jdbc

[英]Unable to connect to jdbc using spark scala

我試圖從 Spark scala 中的 jdbc 讀取數據。 下面是 Databricks 中用 spark scala 編寫的代碼。

val df = (spark
  .read
  .format("jdbc")
  .option("url", <connection-string>)
  .option("dbtable", <table-name>)
  .option("user", <username>)
  .option("password", <password>)
  .option("ssl", True)
  .option("sslmode", "require")
 .load()

我收到以下錯誤消息。

java.sql.SQLNonTransientConnectionException: Could not connect to 10.6.8.86:3306 : PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

有人可以讓我知道如何解決這個問題。

您的主機使用的證書不受 java 信任。

解決方案 1(簡單,不推薦)

禁用證書檢查並始終信任服務器提供的證書。

添加trustServerCertificate屬性。

val df = (spark
  .read
  .format("jdbc")
  .option("url", <connection-string>)
  .option("dbtable", <table-name>)
  .option("user", <username>)
  .option("password", <password>)
  .option("ssl", True)
  .option("trustServerCertificate", True)
  .option("sslmode", "require")
 .load()

解決方案 2(困難,推薦)

獲取證書並將其存儲在系統的受信任存儲中。

在此處閱讀有關它的更多信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM