通过JDBC连接将本地SQL Server数据库连接到数据块时出错 [英] Getting error on connecting to a local SQL Server database to databricks via JDBC connection
问题描述
基本上,我正在尝试使用JDBC连接从数据块连接到本地计算机上的SQL Server数据库.我正在按照
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)
但是我遇到了这个错误
IllegalArgumentException:要求失败:驱动程序无法打开JDBC连接.检查URL:jdbc:mysql://localhost:3306/TestDB
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?
推荐答案
通常用于MySQL数据库的 3306
端口.
Usually 3306
port used for mysql databases.
尝试使用 1433
端口用于 Sql服务器数据库
.
Try with 1433
port for Sql server databases
.
在jdbc网址中使用sqlserver代替mysql jdbcUrl =" jdbc:sqlserver://{0}:{1}; databaseName = {2}"
in jdbc url use sqlserver instead of mysql jdbcUrl = "jdbc:sqlserver://{0}:{1};databaseName={2}"
示例Jdbc网址:
jdbc:sqlserver://localhost:1433; databaseName = AdventureWorks
jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks
这篇关于通过JDBC连接将本地SQL Server数据库连接到数据块时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!