pyjdbc
raw JSON → 0.2.2 verified Mon Apr 27 auth: no python
A Python library that provides a DB-API 2.0 interface using JDBC drivers, enabling Python applications to connect to databases via JDBC bridges. Current version 0.2.2, with infrequent releases.
pip install pyjdbc Common errors
error ImportError: cannot import name 'connect' from 'pyjdbc' ↓
cause Running an older version (0.1.x) where connect was not exported at top level, or incorrect import.
fix
Upgrade to pyjdbc>=0.2.0 and use 'from pyjdbc import connect'.
error py4j.protocol.Py4JError: An error occurred while trying to connect to the Java server ↓
cause Missing or incorrect JDBC driver JAR path, or Java is not installed/configured correctly.
fix
Ensure Java is installed and set JAVA_HOME. Provide the correct absolute path to the JDBC driver JAR in the connect() call.
error py4j.protocol.Py4JNetworkError: Answer from Java side is empty ↓
cause Py4J gateway failed to start, often due to port conflicts or insufficient permissions.
fix
Check that no other process is using port 25333 (default). Restart your Python process.
Warnings
gotcha The connect function requires the 'driver' parameter pointing to a JDBC JAR file; without it, the connection fails. ↓
fix Always provide the full path to the JDBC driver JAR when calling connect().
deprecated Older versions (0.1.x) had a different API; the 'driver' parameter was optional and defaulted to a bundled Hive driver. In 0.2.x, the driver must be explicitly specified. ↓
fix Update your connect() calls to include the driver parameter.
breaking Version 0.2.0 changed the signature of the connect function; the 'driver' parameter is now required and the JAAS configuration handling has changed. ↓
fix Ensure you pass the driver JAR path and review JAAS config usage.
Imports
- connect wrong
import pyjdbccorrectfrom pyjdbc import connect - apache_hive_driver wrong
from pyjdbc import apache_hive_drivercorrectfrom pyjdbc.drivers import apache_hive_driver
Quickstart
from pyjdbc import connect
conn = connect('jdbc:postgresql://localhost:5432/mydb', driver='/path/to/postgresql.jar', user='user', password='pass')
cursor = conn.cursor()
cursor.execute('SELECT 1')
print(cursor.fetchone())
cursor.close()
conn.close()