JyJDBC Pure Jython JDBC dbapi driver

Contents


Overview

Pure Python pep-249 http://www.python.org/peps/pep-0249.html driver for JDBC.

Latest version available from https://hg.sr.ht/~clach04/jyjdbc/

Original written for the Ingres JDBC driver, works with other drivers too.

Targets Jython 2.7.0, 2.5.3, and 2.5.2 (and also works with Jython 2.2).

CPython (and other Python implementations) can make use of JDBC via a bridge to Jython. For example; RPyC, Pyro4, SPyRO, execnet, and SPIRO. Use of a bridge may require additional security attention.

More information https://bitbucket.org/clach04/jyjdbc/wiki/Home


Features

Why?

I needed support for decimal data types which (in 2010) zxJDBC does not have (nor do the other Python/JDBC solutions). I needed to create a number of tests for the decimal type so this was a a major issue, I contributed Decimal support to the IronPython driver but .NET has a limit of 28 decimal places. JyJDBC has a simple internal structure, adding support for new types is trivial.

Right now I recommed using jyjdbc instead of zxJDBC. Current weakness of jyjdbc compared with zxJDBC is that row returning database procedures are not yet implemented and a few types (Binary and ROWID) are not implemented (Java types are returned instead).

A test suite is provided for JyJDBC as well as zxJDBC so the different features/limitations/problems can be compared. There are tests for Ingres and SQLite3.

Demo

The following demos make use of the Ingres DBMS and the Ingres JDBC driver. Connection is made to a database that always exists using Operating System authentication (hence no username/password in the connect statement). SELECT is against a table that always exists in all Ingres databases.

Regular Jython example

This demo connects to a local Ingres DBMS as the current user.

C:\>c:\jython2.5.1\jython.bat
Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54)
[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_02
Type "help", "copyright", "credits" or "license" for more information.
>>> import jyjdbc
>>> con =jyjdbc.connect('iidbdb')  # II_SYSTEM already set, local connection
>>> cur = con.cursor()
>>> cur.execute('select * from iidbconstants')
>>> print cur.description
[(u'user_name', c, None, None, 32, 0, 0), (u'dba_name', c, None, None, 32, 0, 0), (u'system_owner', varchar, None, None, 32, 0, 0)]
>>> print cur.fetchall()
[(u'ingres                          ', u'$ingres                         ', u'$ingres                         ')]
>>>

For more examples and using other databases see the project wiki http://code.google.com/p/jyjdbc/wiki/Examples

CPython access to JDBC

This demo uses RPyC version 3.1.0 from http://pypi.python.org/pypi/RPyC/

Jython starts rpyc_classic.py:

jython rpyc_classic.py

CPython also uses RPyC, using the client:

C:\>python.exe
Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import rpyc
>>> conn = rpyc.classic.connect("localhost")
>>> jyjdbc = conn.modules.jyjdbc
>>> con =jyjdbc.connect('iidbdb')  # II_SYSTEM already set (under RPC), local connection
>>> cur = con.cursor()
>>> cur.execute('select * from iidbconstants')
>>> print cur.description
[(u'user_name', c, None, None, 32, 0, 0), (u'dba_name', c, None, None, 32, 0, 0), (u'system_owner', varchar, None, None, 32, 0, 0)]
>>> print cur.fetchall()
[(u'ingres                          ', u'$ingres                         ', u'$ingres                         ')]

NOTES