2

I’m trying to read data from JDBC in Spark Scala. Below is the code written in Databricks.

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()

I’m getting the following error message:

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

Could someone please let me know how to resolve this issue.

2
  • Is the extra parentheses before Spark a typo? It’s just a detail… Commented Dec 23, 2021 at 2:44
  • Its just a typo. Thank you. Commented Dec 23, 2021 at 14:39

1 Answer 1

3

The certificate used by your host is not trusted by java.

Solution 1 (Easy, not recommended)

Disabled certificate checking and always trust the certificate provided by server.

Add trustServerCertificate property.

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()

Solution 2 (Difficult, Recommended)

Get the certificate and store it in the trusted store of your system.

Read more about it here

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the answer.
Could you show me how to "Disabled certificate checking and always trust the certificate provided by server."?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.