cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Call a Stored Procedure in Azure Synapse with input and output Params

Akshith_Rajesh
New Contributor III
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()

The above code works fine but however I am unable to capture the output Params from Stored Procedure

Can someone please share the snippet to capture output value

1 ACCEPTED SOLUTION

Accepted Solutions

Ryan_Chynoweth
Esteemed Contributor

I think there is an `executeQuery()` function that also works and returns a resultset. Something like this (I have not tested though):

conn = DriverManager.getConnection(url, username, password);
stmt = conn.createStatement();
sql = "SELECT * FROM mytable";
rs = stmt.executeQuery(sql);

View solution in original post

5 REPLIES 5

Ryan_Chynoweth
Esteemed Contributor

I think there is an `executeQuery()` function that also works and returns a resultset. Something like this (I have not tested though):

conn = DriverManager.getConnection(url, username, password);
stmt = conn.createStatement();
sql = "SELECT * FROM mytable";
rs = stmt.executeQuery(sql);

If I print(rs) I am not receiving the expected result

Can you provide more details on the output? I am not entirely sure if the print statement would show the value of rs as it may just show the type of the python object since it is not a string variable.

sivaram_bh
New Contributor II
statement="EXEC procedurename  imputparametre , ? "
driver_manager = spark._sc._gateway.jvm.java.sql.DriverManager
con = driver_manager.getConnection(jdbcUrl, username, pwd)
exec_statement = con.prepareCall(statement)
exec_statement.registerOutParameter(1, spark._sc._gateway.jvm.java.sql.Types.VARCHAR)
df=exec_statement.execute()
# Close connections
result=exec_statement.getString(1)
display(result)
exec_statement.close()
con.close()

judyy
New Contributor III

This blog helped me with the output of the stored procedure: https://medium.com/@judy3.yang/how-to-run-sql-procedure-in-databricks-notebook-e28023555565

Connect with Databricks Users in Your Area

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