=================================================================
JayDeBeApi - bridge from JDBC database drivers to Python DB-API
=================================================================
.. image:: https://img.shields.io/travis/baztian/jaydebeapi/master.svg
:target: https://travis-ci.org/baztian/jaydebeapi
.. image:: https://img.shields.io/coveralls/baztian/jaydebeapi/master.svg
:target: https://coveralls.io/r/baztian/jaydebeapi
.. image:: https://img.shields.io/badge/python-2.7,_3.5,_3.6-blue.svg
:target: https://pypi.python.org/pypi/JayDeBeApi/
.. image:: https://img.shields.io/badge/jython-2.7.2-blue.svg
:target: https://pypi.python.org/pypi/JayDeBeApi/
.. image:: https://img.shields.io/github/tag/baztian/jaydebeapi.svg
:target: https://pypi.python.org/pypi/JayDeBeApi/
.. image:: https://img.shields.io/pypi/dm/JayDeBeApi.svg
:target: https://pypi.python.org/pypi/JayDeBeApi/
The JayDeBeApi module allows you to connect from Python code to
databases using Java `JDBC
<http://java.sun.com/products/jdbc/overview.html>`_. 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 <http://www.jython.org/>`_ 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.
.. contents::
Install
=======
You can get and install JayDeBeApi with `pip <http://pip.pypa.io/>`_
::
$ 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 <https://github.com/baztian/jaydebeapi>`_ 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.7.2.
If you are using cPython ensure that you have installed JPype_
properly. It has been tested with JPype1 0.6.3 and 0.7.5 for Python 3 and
with JPype1 0.6.3 and 0.7.0 for Python 2.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. The second argument is a string with the JDBC connection
URL. Third you can optionally supply a sequence consisting of user and
password or alternatively a dictionary containing arguments that are
internally passed as properties to the Java
``DriverManager.getConnection`` method. See the Javadoc of
``DriverManager`` class for details.
The next parameter to ``connect`` is optional as well 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(50) not null,'
... ' primary key ("CUST_ID"))'
... )
>>> curs.execute("insert into CUSTOMER values (1, 'John')")
>>> curs.execute("select * from CUSTOMER")
>>> curs.fetchall()
[(1, u'John')]
>>> curs.close()
>>> conn.close()
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-8-openjdk python
An alternative way to establish connection using connection
properties:
>>> conn = jaydebeapi.connect("org.hsqldb.jdbcDriver",
... "jdbc:hsqldb:mem:.",
... {'user': "SA", 'password': "",
... 'other_property': "foobar"},
... "/path/to/hsqldb.jar",)
Also using the ``with`` statement might be handy:
>>> with jaydebeapi.connect("org.hsqldb.jdbcDriver",
... "jdbc:hsqldb:mem:.",
... ["SA", ""],
... "/path/to/hsqldb.jar",) as conn:
... with conn.cursor() as curs:
... curs.execute("select count(*) from CUSTOMER")
... curs.fetchall()
[(1,)]
Supported databases
===================
In theory *every database with a suitable JDBC driver should work*. It
is confirmed to work with the following databases:
* SQLite
* Hypersonic SQL (HSQLDB)
* IBM DB2
* IBM DB2 for mainframes
* Oracle
* Teradata DB
* Netezza
* Mimer DB
* Microsoft SQL Server
* MySQL
* PostgreSQL
* many more...
Contributing
============
Please submit `bugs and patches
<https://github.com/baztian/jaydebeapi/issues>`_. 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
- 1.2.3 - 2020-06-12
- Make pip install for Python 2 work by changing JPype1 requirement to older
version
- Make pip install for Jython work by removing JPype1 requirement for Jython
- Removed cursor destructor to avoid issues with some JPype versions (please
make sure you're always closing your cursors properly)
- 1.2.2 - 2020-06-04
- Return (big) decimal types as long value if scale is zero (thanks
to @ministat)
- Fix `DECIMAL` and `NUMERIC` type conversion for Jython
- 1.2.1 - 2020-05-27
- Increased thread safety. Should resolve some of the
`No suitable driver found` errors (thanks to @thealmightygrant)
- 1.2.0 - 2020-05-22
- Added compatibility to JPype1 0.7.2+ (thanks to @dpd)
- Support `with` statement (thanks to @Szczepanov)
- 1.1.2 - 2019-09-02
- Added compatibility to JPype1 0.7 (thanks to @Iverian, @Thrameos)
- Dropped python 2.6 support
- Fix build working with newer Maven versions
- Accidently force-pushed to master branch. Sorry for that.
- 1.1.1 - 2017-03-21
- Don't fail on dates before 1900 on Python < 3.
- 1.1.0 - 2017-03-19
- Support BIT and TINYINT type mappings (thanks @Mokubyow for
reporting the issue).
- 1.0.0 - 2017-01-10
- Allow for db properties to be passed to the connect
method. *Probably incompatible to code based on previous
versions.* See documentation of the connect method. (Thanks
@testlnord for you efforts and the patience.)
- New major version due to possible api incompatibility.
- 0.2.0 - 2015-04-26
- Python 3 support (requires JPype1 >= 0.6.0).
- 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)
.. _DB-API: http://www.python.org/dev/peps/pep-0249/
.. _JPype: https://pypi.python.org/pypi/JPype1/
Raw data
{
"_id": null,
"home_page": "https://github.com/baztian/jaydebeapi",
"name": "JayDeBeApi",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "db api java jdbc bridge connect sql jpype jython",
"author": "Bastian Bowe",
"author_email": "bastian.dev@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/5c/8c/f27750106bf1fba33f92d83fb866af164179f7046495bc5a61fae26d9475/JayDeBeApi-1.2.3.tar.gz",
"platform": "",
"description": "=================================================================\n JayDeBeApi - bridge from JDBC database drivers to Python DB-API\n=================================================================\n\n.. image:: https://img.shields.io/travis/baztian/jaydebeapi/master.svg\n :target: https://travis-ci.org/baztian/jaydebeapi\n\n.. image:: https://img.shields.io/coveralls/baztian/jaydebeapi/master.svg\n :target: https://coveralls.io/r/baztian/jaydebeapi\n\n.. image:: https://img.shields.io/badge/python-2.7,_3.5,_3.6-blue.svg\n :target: https://pypi.python.org/pypi/JayDeBeApi/\n\n.. image:: https://img.shields.io/badge/jython-2.7.2-blue.svg\n :target: https://pypi.python.org/pypi/JayDeBeApi/\n\n.. image:: https://img.shields.io/github/tag/baztian/jaydebeapi.svg\n :target: https://pypi.python.org/pypi/JayDeBeApi/\n\n.. image:: https://img.shields.io/pypi/dm/JayDeBeApi.svg\n :target: https://pypi.python.org/pypi/JayDeBeApi/\n\nThe JayDeBeApi module allows you to connect from Python code to\ndatabases using Java `JDBC\n<http://java.sun.com/products/jdbc/overview.html>`_. It provides a\nPython DB-API_ v2.0 to that database.\n\nIt works on ordinary Python (cPython) using the JPype_ Java\nintegration or on `Jython <http://www.jython.org/>`_ to make use of\nthe Java JDBC driver.\n\nIn contrast to zxJDBC from the Jython project JayDeBeApi let's you\naccess a database with Jython AND Python with only minor code\nmodifications. JayDeBeApi's future goal is to provide a unique and\nfast interface to different types of JDBC-Drivers through a flexible\nplug-in mechanism.\n\n.. contents::\n\nInstall\n=======\n\nYou can get and install JayDeBeApi with `pip <http://pip.pypa.io/>`_\n::\n\n $ pip install JayDeBeApi\n\nIf you want to install JayDeBeApi in Jython make sure to have pip or\nEasyInstall available for it.\n\nOr you can get a copy of the source by cloning from the `JayDeBeApi\ngithub project <https://github.com/baztian/jaydebeapi>`_ and install\nwith ::\n\n $ python setup.py install\n\nor if you are using Jython use ::\n\n $ jython setup.py install\n\nIt has been tested with Jython 2.7.2.\n\nIf you are using cPython ensure that you have installed JPype_\nproperly. It has been tested with JPype1 0.6.3 and 0.7.5 for Python 3 and\nwith JPype1 0.6.3 and 0.7.0 for Python 2.7. Older JPype\ninstallations may cause problems.\n\nUsage\n=====\n\nBasically you just import the ``jaydebeapi`` Python module and execute\nthe ``connect`` method. This gives you a DB-API_ conform connection to\nthe database.\n\nThe first argument to ``connect`` is the name of the Java driver\nclass. The second argument is a string with the JDBC connection\nURL. Third you can optionally supply a sequence consisting of user and\npassword or alternatively a dictionary containing arguments that are\ninternally passed as properties to the Java\n``DriverManager.getConnection`` method. See the Javadoc of\n``DriverManager`` class for details.\n\nThe next parameter to ``connect`` is optional as well and specifies\nthe jar-Files of the driver if your classpath isn't set up\nsufficiently yet. The classpath set in ``CLASSPATH`` environment\nvariable will be honored. See the documentation of your Java runtime\nenvironment.\n\nHere is an example:\n\n>>> import jaydebeapi\n>>> conn = jaydebeapi.connect(\"org.hsqldb.jdbcDriver\",\n... \"jdbc:hsqldb:mem:.\",\n... [\"SA\", \"\"],\n... \"/path/to/hsqldb.jar\",)\n>>> curs = conn.cursor()\n>>> curs.execute('create table CUSTOMER'\n... '(\"CUST_ID\" INTEGER not null,'\n... ' \"NAME\" VARCHAR(50) not null,'\n... ' primary key (\"CUST_ID\"))'\n... )\n>>> curs.execute(\"insert into CUSTOMER values (1, 'John')\")\n>>> curs.execute(\"select * from CUSTOMER\")\n>>> curs.fetchall()\n[(1, u'John')]\n>>> curs.close()\n>>> conn.close()\n\nIf you're having trouble getting this work check if your ``JAVA_HOME``\nenvironmentvariable is set correctly. For example I have to set it on\nmy Ubuntu machine like this ::\n\n $ JAVA_HOME=/usr/lib/jvm/java-8-openjdk python\n\nAn alternative way to establish connection using connection\nproperties:\n\n>>> conn = jaydebeapi.connect(\"org.hsqldb.jdbcDriver\",\n... \"jdbc:hsqldb:mem:.\",\n... {'user': \"SA\", 'password': \"\",\n... 'other_property': \"foobar\"},\n... \"/path/to/hsqldb.jar\",)\n\nAlso using the ``with`` statement might be handy:\n\n>>> with jaydebeapi.connect(\"org.hsqldb.jdbcDriver\",\n... \"jdbc:hsqldb:mem:.\",\n... [\"SA\", \"\"],\n... \"/path/to/hsqldb.jar\",) as conn:\n... with conn.cursor() as curs:\n... curs.execute(\"select count(*) from CUSTOMER\")\n... curs.fetchall()\n[(1,)]\n\nSupported databases\n===================\n\nIn theory *every database with a suitable JDBC driver should work*. It\nis confirmed to work with the following databases:\n\n* SQLite\n* Hypersonic SQL (HSQLDB)\n* IBM DB2\n* IBM DB2 for mainframes\n* Oracle\n* Teradata DB\n* Netezza\n* Mimer DB\n* Microsoft SQL Server\n* MySQL\n* PostgreSQL\n* many more...\n\nContributing\n============\n\nPlease submit `bugs and patches\n<https://github.com/baztian/jaydebeapi/issues>`_. All contributors\nwill be acknowledged. Thanks!\n\nLicense\n=======\n\nJayDeBeApi is released under the GNU Lesser General Public license\n(LGPL). See the file ``COPYING`` and ``COPYING.LESSER`` in the\ndistribution for details.\n\n\nChangelog\n=========\n\n- Next version - unreleased\n- 1.2.3 - 2020-06-12\n\n - Make pip install for Python 2 work by changing JPype1 requirement to older\n version\n - Make pip install for Jython work by removing JPype1 requirement for Jython\n - Removed cursor destructor to avoid issues with some JPype versions (please\n make sure you're always closing your cursors properly)\n\n- 1.2.2 - 2020-06-04\n\n - Return (big) decimal types as long value if scale is zero (thanks\n to @ministat)\n - Fix `DECIMAL` and `NUMERIC` type conversion for Jython\n\n- 1.2.1 - 2020-05-27\n\n - Increased thread safety. Should resolve some of the\n `No suitable driver found` errors (thanks to @thealmightygrant)\n\n- 1.2.0 - 2020-05-22\n\n - Added compatibility to JPype1 0.7.2+ (thanks to @dpd)\n - Support `with` statement (thanks to @Szczepanov)\n\n- 1.1.2 - 2019-09-02\n\n - Added compatibility to JPype1 0.7 (thanks to @Iverian, @Thrameos)\n - Dropped python 2.6 support\n - Fix build working with newer Maven versions\n - Accidently force-pushed to master branch. Sorry for that.\n\n- 1.1.1 - 2017-03-21\n\n - Don't fail on dates before 1900 on Python < 3.\n\n- 1.1.0 - 2017-03-19\n\n - Support BIT and TINYINT type mappings (thanks @Mokubyow for\n reporting the issue).\n\n- 1.0.0 - 2017-01-10\n\n - Allow for db properties to be passed to the connect\n method. *Probably incompatible to code based on previous\n versions.* See documentation of the connect method. (Thanks\n @testlnord for you efforts and the patience.)\n\n - New major version due to possible api incompatibility.\n\n- 0.2.0 - 2015-04-26\n\n - Python 3 support (requires JPype1 >= 0.6.0).\n\n- 0.1.6 - 2015-04-10\n\n - Fix Jython handling of Java exceptions that don't subclass python Exception\n\n - Enrich exceptions with message from java SQLExceptions\n\n - Be more specific about DB API exceptions: Distinguish DatabaseError and\n InterfaceError.\n\n - Fix typo LONGNARCHAR vs LONGVARCHAR (thanks @datdo for reporting #4)\n\n- 0.1.5 - 2015-03-02\n\n - Add version number to module.\n\n - Improve robustness of java to python type conversion.\n\n - Support Time type.\n\n - Add DB-API compliant exception handling.\n\n - Minor documentation improvements.\n\n - Some development related changes (Host project at github, use\n Travis CI, use JPype1 for tests).\n\n- 0.1.4 - 2013-10-29\n\n - More convenient way to setup Java classpath. *Important note*\n check the changes to the ``connect`` method and adapt your code.\n\n - Honor ``CLASSPATH`` if used in JPype mode.\n\n - Set ``.rowcount`` properly.\n\n - Changed signature of ``.setoutputsize()`` to be DB-API compliant.\n\n- 0.1.3 - 2011-01-27\n\n - Fixed DB-API_ violation: Use ``curs.execute('foo ?', (bar, baz))``\n instead of ``curs.execute('foo ?', bar, baz)``.\n\n - Free resources after ``executemany`` call.\n\n - Improved type handling. Initial support for BLOB columns.\n\n- 0.1.2 - 2011-01-25\n\n - ``easy_install JayDeBeApi`` should really work.\n\n- 0.1.1 - 2010-12-12\n\n - Fixed bug #688290 \"NULL values with converters error on fetch\".\n - Fixed bug #684909 \"Selecting ROWIDs errors out on fetch\".\n\n- 0.1 - 2010-08-10\n\n - Initial release.\n\nTo do\n=====\n\n- Extract Java calls to separate Java methods to increase performance.\n- Check if https://code.launchpad.net/dbapi-compliance can help making\n JayDeBeApi more DB-API compliant.\n- Test it on different databases and provide a flexible db specific\n pluign mechanism.\n- SQLAlchemy modules (separate project)\n\n.. _DB-API: http://www.python.org/dev/peps/pep-0249/\n.. _JPype: https://pypi.python.org/pypi/JPype1/\n\n\n",
"bugtrack_url": null,
"license": "GNU LGPL",
"summary": "Use JDBC database drivers from Python 2/3 or Jython with a DB-API.",
"version": "1.2.3",
"split_keywords": [
"db",
"api",
"java",
"jdbc",
"bridge",
"connect",
"sql",
"jpype",
"jython"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "9bf5f800efbc3037ecd7a87036d1e3ed",
"sha256": "fbfbc7e41d7b35af08df6376a73637820c71a1373b40244b135bd07f3e865c81"
},
"downloads": -1,
"filename": "JayDeBeApi-1.2.3-py2-none-any.whl",
"has_sig": false,
"md5_digest": "9bf5f800efbc3037ecd7a87036d1e3ed",
"packagetype": "bdist_wheel",
"python_version": "py2",
"requires_python": null,
"size": 26328,
"upload_time": "2020-06-12T07:03:30",
"upload_time_iso_8601": "2020-06-12T07:03:30.958896Z",
"url": "https://files.pythonhosted.org/packages/53/e4/6303cc884ab27bd8a18a7e13f045cc2cbd43339d3b298587dc137090b2a5/JayDeBeApi-1.2.3-py2-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "eee4ed2ee8bd59b8d239b328aaf552df",
"sha256": "d6256bdad1e14414225fbc839f7d56922ea3abc06153f3a57490fee909fecd64"
},
"downloads": -1,
"filename": "JayDeBeApi-1.2.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "eee4ed2ee8bd59b8d239b328aaf552df",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 26328,
"upload_time": "2020-06-12T07:03:25",
"upload_time_iso_8601": "2020-06-12T07:03:25.434747Z",
"url": "https://files.pythonhosted.org/packages/ff/1f/6a627c9bd7dea13235b65fce0fff987507269d41f957c578031796f70319/JayDeBeApi-1.2.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "55770b87148b173434535d84ff33f7c6",
"sha256": "f25e9307fbb5960cb035394c26e37731b64cc465b197c4344cee85ec450ab92f"
},
"downloads": -1,
"filename": "JayDeBeApi-1.2.3.tar.gz",
"has_sig": false,
"md5_digest": "55770b87148b173434535d84ff33f7c6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 32929,
"upload_time": "2020-06-12T07:03:27",
"upload_time_iso_8601": "2020-06-12T07:03:27.204461Z",
"url": "https://files.pythonhosted.org/packages/5c/8c/f27750106bf1fba33f92d83fb866af164179f7046495bc5a61fae26d9475/JayDeBeApi-1.2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2020-06-12 07:03:27",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "baztian",
"github_project": "jaydebeapi",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "jaydebeapi"
}