'Why I'm getting an error in DataBricks connection with a SQL database?

I am trying to connect to a SQL Server but somehow i'm getting the below error when trying to connect to db from databricks using Python:

Error:java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbd.SQLServerDriver

My connection code is the next one:

jdbcHostname = "hostname"
jdbcDatabase = "databasename"
jdbcPort = port

username = 'username'
password = 'password'

jdbcUrl = "jdbc:sqlserver://{0}:{1};database={2}".format(jdbcHostname, jdbcPort, jdbcDatabase)
connectionProperties = {
    "user" : username,
    "password" : password,
    "driver" : "com.microsoft.sqlserver.jdbd.SQLServerDriver"
}

The last code works, but when I try to execute a query I got the mentioned error coming out from the second code line from the next block:

pushdown_query = "select * from table"
df = spark.read.jdbc(url=jdbcUrl, table=pushdown_query, properties=connectionProperties)
display(df)

I tried to install different connectors but I have not been lucky with it, could you help me?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source