Skip to main content

A bridge from JDBC database drivers to Python DB-API.

Project description

https://img.shields.io/travis/baztian/jaydebeapi/master.svg https://img.shields.io/coveralls/baztian/jaydebeapi/master.svg https://img.shields.io/badge/python-2.6,_2.7-blue.svg https://img.shields.io/badge/jython-2.5.3,_2.7--rc1-blue.svg https://pypip.in/version/JayDeBeApi/badge.svg https://pypip.in/download/JayDeBeApi/badge.svg

The JayDeBeApi module allows you to connect from Python code to databases using Java JDBC. It provides a Python DB-API v2.0 to that database.

It works on ordinary Python (cPython) using the JPype Java integration or on Jython to make use of the Java JDBC driver.

In contrast to zxJDBC from the Jython project JayDeBeApi let’s you access a database with Jython AND Python with only minor code modifications. JayDeBeApi’s future goal is to provide a unique and fast interface to different types of JDBC-Drivers through a flexible plug-in mechanism.

Install

You can get and install JayDeBeApi with pip

$ pip install JayDeBeApi

If you want to install JayDeBeApi in Jython make sure to have pip or EasyInstall available for it.

Or you can get a copy of the source by cloning from the JayDeBeApi github project and install with

$ python setup.py install

or if you are using Jython use

$ jython setup.py install

It has been tested with Jython 2.5.3 an 2.7-b3.

If you are using cPython ensure that you have installed JPype properly. It has been tested with JPype1 0.5.7. Older JPype installations may cause problems.

Usage

Basically you just import the jaydebeapi Python module and execute the connect method. This gives you a DB-API conform connection to the database.

The first argument to connect is the name of the Java driver class. Then you can supply a single argument or a sequence of arguments that are internally passed to the Java DriverManager.getConnection method. Usually this is the JDBC connection URL. See the Javadoc of DriverManager class for details.

The next parameter to connect is optional and specifies the jar-Files of the driver if your classpath isn’t set up sufficiently yet. The classpath set in CLASSPATH environment variable will be honored. See the documentation of your Java runtime environment.

Here is an example:

>>> import jaydebeapi
>>> conn = jaydebeapi.connect('org.hsqldb.jdbcDriver',
...                           ['jdbc:hsqldb:mem:.', 'SA', ''],
...                           '/path/to/hsqldb.jar',)
>>> curs = conn.cursor()
>>> curs.execute('create table CUSTOMER'
...                '("CUST_ID" INTEGER not null,'
...                ' "NAME" VARCHAR not null,'
...                ' primary key ("CUST_ID"))'
...             )
>>> curs.execute("insert into CUSTOMER values (1, 'John')")
>>> curs.execute("select * from CUSTOMER")
>>> curs.fetchall()
[(1, u'John')]

If you’re having trouble getting this work check if your JAVA_HOME environmentvariable is set correctly. For example I have to set it on my Ubuntu machine like this

$ JAVA_HOME=/usr/lib/jvm/java-6-openjdk python

Supported databases

In theory every database with a suitable JDBC driver should work. It is known to work with the following databases:

Database

JDBC driver

Supported

Remarks

SQLite 3

SqliteJDBC v056

Good

Can’t interpret selected BLOBs correctly.

Sqlite Java Wrapper javasqlite-20110106-win32

Medium

Weird type handling.

Hypersonic SQL (HSQLDB) 1.8.1.3

Builtin

Very Good

No BLOB support by database.

Hypersonic SQL (HSQLDB) 2

Builtin

Medium

Weird decimal type conversions. No BLOB support.

IBM DB2 for z/OS

JDBC type 4 drivers from IBM (db2jcc.jar)

Medium.

Not thoroughly tested but seems to work without problems.

Oracle 11g

Oracle Thin Driver

Medium

Not thoroughly tests. No support for rading of timestamps yet.

Teradata DB

terajdbc4.jar

Medium

A user reported success.

Other databases

Other JDBC drivers

Unkown

Please test yourself and report the results.

Contributing

Please submit bugs and patches. All contributors will be acknowledged. Thanks!

License

JayDeBeApi is released under the GNU Lesser General Public license (LGPL). See the file COPYING and COPYING.LESSER in the distribution for details.

Changelog

  • Next version - unreleased

  • 0.1.6 - 2015-04-10

    • Fix Jython handling of Java exceptions that don’t subclass python Exception

    • Enrich exceptions with message from java SQLExceptions

    • Be more specific about DB API exceptions: Distinguish DatabaseError and InterfaceError.

    • Fix typo LONGNARCHAR vs LONGVARCHAR (thanks @datdo for reporting #4)

  • 0.1.5 - 2015-03-02

    • Add version number to module.

    • Improve robustness of java to python type conversion.

    • Support Time type.

    • Add DB-API compliant exception handling.

    • Minor documentation improvements.

    • Some development related changes (Host project at github, use Travis CI, use JPype1 for tests).

  • 0.1.4 - 2013-10-29

    • More convenient way to setup Java classpath. Important note check the changes to the connect method and adapt your code.

    • Honor CLASSPATH if used in JPype mode.

    • Set .rowcount properly.

    • Changed signature of .setoutputsize() to be DB-API compliant.

  • 0.1.3 - 2011-01-27

    • Fixed DB-API violation: Use curs.execute('foo ?', (bar, baz)) instead of curs.execute('foo ?', bar, baz).

    • Free resources after executemany call.

    • Improved type handling. Initial support for BLOB columns.

  • 0.1.2 - 2011-01-25

    • easy_install JayDeBeApi should really work.

  • 0.1.1 - 2010-12-12

    • Fixed bug #688290 “NULL values with converters error on fetch”.

    • Fixed bug #684909 “Selecting ROWIDs errors out on fetch”.

  • 0.1 - 2010-08-10

    • Initial release.

To do

  • Extract Java calls to separate Java methods to increase performance.

  • Check if https://code.launchpad.net/dbapi-compliance can help making JayDeBeApi more DB-API compliant.

  • Test it on different databases and provide a flexible db specific pluign mechanism.

  • SQLAlchemy modules (separate project)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

JayDeBeApi-0.1.6.tar.gz (34.8 kB view details)

Uploaded Source

Built Distribution

JayDeBeApi-0.1.6-py2-none-any.whl (14.4 kB view details)

Uploaded Python 2

File details

Details for the file JayDeBeApi-0.1.6.tar.gz.

File metadata

  • Download URL: JayDeBeApi-0.1.6.tar.gz
  • Upload date:
  • Size: 34.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for JayDeBeApi-0.1.6.tar.gz
Algorithm Hash digest
SHA256 3234c39d2d3d36f876dab9919db13a2eb4d76382a21c92cee047c19da8332b31
MD5 258753f2b5680cc46e5b36674fd2b564
BLAKE2b-256 77a427fd1888dc24bcd8f870e733bef49a273145d7431d7b41a8c3d6813c09bc

See more details on using hashes here.

Provenance

File details

Details for the file JayDeBeApi-0.1.6-py2-none-any.whl.

File metadata

File hashes

Hashes for JayDeBeApi-0.1.6-py2-none-any.whl
Algorithm Hash digest
SHA256 c94ef00d65f6ac02040586b34cdbc2038ee7ae79c7dac0f0f110b5729355d986
MD5 34a2b6acea2c13b35d466eaaebb0ebed
BLAKE2b-256 22479017f3bbe6c109d4f3d241ec08ce6d1428f265984c0e5c07d419c593b4fe

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page