06-07-2022 08:33 AM
I know how to do it with spark, and read/write tables (like https://docs.microsoft.com/en-gb/azure/databricks/data/data-sources/sql-databases#python-example )
But this time, I need to only update a field of a specific row in a table. I do not think I can do that with spark jdbc (mode for append or overwrite)
Then, I tried to use jaydebeapi and pymssql, but no success.
jaydebeapi would: Class com.microsoft.sqlserver.jdbc.SQLServerDriver is not found
Also tried to use pyodbc, but failed to install mssql odbc driver.
what is the best practice for that usecase?
06-09-2022 08:26 AM
thanks for the link.
I am maybe wrong, but they describe how to connect with spark. They do not provide a connection engine that we could use directly (like with pyodbc) or an engine that we could use in pandas, for example.
06-10-2022 07:36 AM
thanks!
but here again, it goes through the spark interface.
Therefore, comes with spark limits. For example, when write, we can "overwrite" or "append".
What if we want to, only, update an existing row?
Could load all the table, update it in spark, and write it back. But if the table is large, and we need to do that in a very short time?
06-22-2022 08:28 AM
sure!
pip install jaydebeapi pymssql
import jaydebeapi
import pymssql
pymssql.connect(server='xxxxxxxxxxxxxxxxx.database.windows.net',
user='sqladmin@xxxxxxxxxxxxxxxxx',
password='1234',
database="yyyyyyyyyyyyyyyyy",
port='1433',
)
pymssql.connect(server='xxxxxxxxxxxxxxxxx.database.windows.net',
user='sqladmin',
password='1234',
database="yyyyyyyyyyyyyyyyy",
port='1433',
)
jaydebeapi.connect('com.microsoft.sqlserver.jdbc.SQLServerDriver',
'jdbc:sqlserver://xxxxxxxxxxxxxxxxx.database.windows.net:1433;database=yyyyyyyyyyyyyyyyy',
['sqladmin', '1234'])
bellow, outputs:
OperationalError: (20009, b'DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (xxxxxxxxxxx.database.windows.net)\nNet-Lib error during Connection refused (111)\nDB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (xxxxxxxxxxxxx.database.windows.net)\nNet-Lib error during Connection refused (111)\n')
same for the second call.
and last, for jaydebeapi
TypeError: Class com.microsoft.sqlserver.jdbc.SQLServerDriver is not found
08-23-2024 04:05 AM
Hi @yopbibo - Did you find the answer that you were looking for? i.e. update individual rows in db tables?
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.
If there isn’t a group near you, start one and help create a community that brings people together.
Request a New Group