How to run stored procedure on SQL server from Spark (Databricks) JDBC python?

Yes, it’s possible you just need to get access to the underlying Java classes of JDBC, something like this:

# the first line is the main entry point into JDBC world
driver_manager = spark._sc._gateway.jvm.java.sql.DriverManager
connection = driver_manager.getConnection(mssql_url, mssql_user, mssql_pass)
connection.prepareCall("EXEC sys.sp_tables").execute()
connection.close()

Leave a Comment