0

Basically I'm trying to connect to a SQL Server database on my local machine from databricks using a JDBC connection. I'm following the procedure mentioned in the documentation as shown here on the databricks website.

I used the following code as mentioned on the website:

jdbcHostname = "localhost"
jdbcDatabase = "TestDB"
jdbcPort = "3306"

jdbcUrl = "jdbc:mysql://{0}:{1}/{2}".format(jdbcHostname, jdbcPort, jdbcDatabase)
connectionProperties = {
    "jdbcUsername" : "user1",
    "jdbcPassword" : "pass1",
    "driver" : "com.microsoft.sqlserver.jdbc.SQLServerDriver"
     }

pushdown_query = "SELECT * FROM dbo.customer"
df = spark.read.jdbc(url=jdbcUrl, table=pushdown_query,properties=connectionProperties)
display(df)

But I'm getting this error

IllegalArgumentException: requirement failed: The driver could not open a JDBC connection. Check the URL: jdbc:mysql://localhost:3306/TestDB

Can anyone explain why is it happening? How can I fix this error?

1 Answer 1

2

Usually 3306 port used for mysql databases.

Try with 1433 port for Sql server databases.

in jdbc url use sqlserver instead of mysql jdbcUrl = "jdbc:sqlserver://{0}:{1};databaseName={2}"


Example Jdbc url:

jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks

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

2 Comments

com.microsoft.sqlserver.jdbc.SQLServerException: The port number 1433/TestDB is not valid.
Try with jdbc:sqlserver://localhost:1433;databaseName=TestDB

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.