cancel
Showing results for 
Search instead for 
Did you mean: 
Administration & Architecture
Explore discussions on Databricks administration, deployment strategies, and architectural best practices. Connect with administrators and architects to optimize your Databricks environment for performance, scalability, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 

Proper way to collect Statement ID from JDBC Connection

harripy
New Contributor III

Hi, 

We are executing DML calls on Databricks SQL Warehouse programmatically, with Java and Python.

There can be thousands of executions running on daily level, so in case of an error occurs, it would be very beneficial to spot the Statement ID of the failed execution.

We just recently discovered that the Statement ID can be retrieved on Python SDK as follows from the connection cursor:

 

if cursor and cursor.active_op_handle is not None:
    queryId = UUID(bytes= cursor.active_op_handle.operationId.guid)

 

But what would be equivalent for doing the same on Java SDK?

We are getting the Java Connection from the DriverManager.getConnection(jdbcUrl, props) -call.

2 REPLIES 2

Kaniz
Community Manager
Community Manager

Hi @harripy

To retrieve the Statement ID from a Databricks SQL Warehouse execution using the Java SDK, you can follow these steps:

  1. Execute the Query: First, execute your DML query using the Java JDBC connection. You can use the java.sql.Statement or java.sql.PreparedStatement to execute the query.

  2. Retrieve the Result Set: After executing the query, you’ll get a result set. Iterate through the result set to process the data.

  3. Access the Statement ID: Unfortunately, the Java SDK doesn’t provide a direct equivalent to the Python SDK’s cursor.active_op_handle.operationId.guid.

    If you need further assistance, feel free to ask! 😊

harripy
New Contributor III

Thanks @Kaniz for the suggestion, but I still would need the Statement ID for further analysis (as Query History performs best with direct ID). - Any way to Unwrap the java.sql.Connection interface to the implementing class and getting the metadata through it?

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!