1

I am trying to execute a python code from Databricks which primarily establish a connection from Python to SQL server using JDBC.

I used 'jaydebeapi' python library and when I run the code it gives error saying "JayDeBeApi throws AttributeError: '_jpype.PyJPField' object has no attribute 'getStaticAttribute' "

I searched in the internet and found the Jpype library is used in jaydebeapi is the problem and I downgraded the same to 0.6.3 version.

But still I am getting the same error. Can anyone explain me how to make this change and run in databricks.

Or is there any alternative library which I can use.

2 Answers 2

1

Why not directly follow the offical documents of databricks below to install Microsoft JDBC Driver for SQL Server for Spark Connector and refer to the sample code of Python using JDBC connect SQL Server.

  1. SQL Databases using the Apache Spark Connector
  2. SQL Databases using JDBC and its Python example with the jdbc url of MS SQL Server

If you were using Azure, there are the same documents for Azure Databricks, as below.

  1. SQL Databases using the Apache Spark Connector for Azure Databricks
  2. SQL Databases using JDBC for Azure Databricks

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Peter. This project is something they have already used jaydebeapi on hdinsight cluster.I don't want to change huge things on the code. I use a similar lib py2jdbc which works fine.
0

This is a known issue with JayDeBeApi, you may check out the issue on GitHub.

Due to a bug in 0.6.3 private variables were exposed as part of the interface. Also 0.6.3 had a default class customizer which automatically created a property to get and set if the methods matched a Java bean pattern. This property customizer was loaded late after many common java.lang classes were already loaded, and was not retroactive thus only user loaded classes that happened after initializer would have the customization. The private variable bug would mask the property customizer as the property customizer was not to override fields. Some libraries were unknowingly accessing private variables assuming they were using the property customizer. The customizer was both unnecessary and resulted in frequent errors for new programmers. The buggy behavior has been removed and the problematic property customizer has been disable by default in 0.7.

Add lines to the module to enable the old property behavior. But this will not reenable the previous buggy access to private variables. Thus code that was exploiting the previous behavior which bypassed the getter/setter of java will need to use the reflection API.

To enable the property customizer, use

try:
   import jpype.beans
except ImportError:
   pass

Hope this helps.

1 Comment

Thanks, I am new to Python, Is the above code needs to be added in the .py script where it actually runs the jaydebeapi ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.