Getting error on connecting to a local SQL Server database to databricks via JDBC connection

房东的猫 提交于 2021-01-29 17:40:34

问题


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:


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



来源:https://stackoverflow.com/questions/62624059/getting-error-on-connecting-to-a-local-sql-server-database-to-databricks-via-jdb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!