Jython and zxJDBC package

Dave M. david.g.morgenthaler at lmco.com
Tue Sep 3 22:03:12 EDT 2002

> > Is anyone here using the zxJDBC package as described in "Jython
> > Essentials" to access a MySQL database?
> > 
> > When I try to run the sample program (Example 10-1, p. 164), I receive
> > a NoClassDefFoundError: org/gjt/mm/mysql/Statement in
> > MySQLDataHandler.  Decompiling MySQLDataHandler reveals an explicit
> > reference to org.gjt.mm.mysql.Statement; but this class isn't in the
> > Connector/J library.  Am I missing something here?
> > 
> > I'm using Jython 2.1 and Connector/J 2.0.14.
> It looks like MySQLDataHandler wants to use the MM.MySQL package,
> which can be found here:
>   http://sourceforge.net/projects/mmmysql
The example in the book does indeed expect the use of MySQL. I don't
know about Connnetor/J, but, for example, the following works with
Sun's JDBC-ODBC bridge driver talking to an Access database:

import com.ziclix.python.sql as sql
dburl, user, pw, drv = ("jdbc:odbc:testTrack","",
db = sql.zxJDBC.connect(dburl, user, pw, drv)
cursor = db.cursor()
#cursor.datahandler = sql.handler.MySQLDataHandler(cursor.datahandler)
cursor.execute("SELECT * FROM trackTable")

for item in cursor.fetchall():
    print item
-----------end code----------
Be sure that, e.g., sun.jdbc.odbc.JdbcOdbcDriver is on your Jython

Note also the setting of a specific datahandler is commented out.
zxJDBC ships with custom drivers for
Oracle (sql.handler.OracleDataHandler),
Informix (sql.handler.InformixDataHandler),
Postgresql (sql.handler.PostgresqlDataHandler), and
SQLServer (sql.handler.SQLServerDataHandler) 
in addition to the MySQLDataHandler. If you're not using one of these,
the default data handler will work.

More information about the Python-list mailing list