Skip to main content

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.

It has been tested with Hypersonic SQL (HSQLDB) and IBM DB2 for z/OS.

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 easy_install

$ easy_install JayDeBeApi

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

Or you can get a copy of the source branch using bzr by running

$ bzr branch lp:jaydebeapi

and install it with

$ python setup.py install

or if you are using Jython use

$ jython setup.py install

It has been tested with Jython 2.5.2.

If you are using cPython ensure that you have installed JPype properly. It has been tested with JPype 0.5.4.

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. The rest of the arguments are internally passed to the Java DriverManager.getConnection method. See the Javadoc of DriverManager class for details.

Here is an example:

>>> import jaydebeapi
>>> conn = jaydebeapi.connect('org.hsqldb.jdbcDriver',
...                           'jdbc:hsqldb:mem', 'SA', '')
>>> 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')]

You probably have to configure Jython or JPype to actually be able to access the database driver’s jar files. If I want to connect to a HSQL in memory database on my Ubuntu machine I’m starting Python by running

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

Now I have to configure JPype

>>> jar = '/path/to/my/driver/hsqldb.jar'
>>> args='-Djava.class.path=%s' % jar
>>> jpype.startJVM(jvm_path, args)

or in Jython I have to

>>> jar = '/path/to/my/driver/hsqldb.jar'
>>> import sys
>>> sys.path.append(jar)

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

  • 0.1.1

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

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

  • 0.1

    • Initial release

To do

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

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

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

  • SQLAlchemy modules (seperate project)

Release files for JayDeBeApi 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for JayDeBeApi 0.1.1
File Size Uploaded
JayDeBeApi-0.1.1.tar.gz 6.0 kB Details

Release files / JayDeBeApi-0.1.1.tar.gz

Download URL JayDeBeApi-0.1.1.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
edf5a1aeff2ae2418f84d02db71f89cd295118ed103616578c1be7b2b74c2415
BLAKE2b-256 checksum
How to use checksums
9e49fd4c2acc1e3692d345f17e9bbe4b83e3b65d82dab8744c1f0a3d86ae591f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.2.3

3 release files

1.2.2

3 release files

1.2.1

3 release files

1.2.0

2 release files

1.1.1

3 release files

1.1.0

3 release files

1.0.0

3 release files

0.2.0

3 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

This release

0.1.1 This release

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page