问题
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