JDBC <--> Python
Tom Bryan
tbryan at python.net
Tue Jun 3 23:58:02 EDT 2003
Elam wrote:
> I've been programming with Python for about a year now and would like
> to use it for some CGI programming. The programming involves
> accessing a proprietary db whose only access methods is thru JDBC.
Uh oh. What DB? Have you checked for a Python DB module? Are you sure
that there's no way to access the DB from C code?
> I've used Jython, but it's somewhat slow and from what I read, not
> really suitable for CGI work.
I suppose you could write Java servlets in Jython. The servlet engine would
be heavy, but then you wouldn't incur the speed hit of loading Jython for
each page hit.
> Is there any generic framework ala DBI for python? Any suggestions
> for alternatives?
Yes, but even Perl's DBI won't help you here. The Python DB API spec (look
for the DB-SIG on www.python.org) and Perl's DBI just define an interface
that database module writers are supposed to expose. Then, someone writes
a database module, such as psycopg for PostgreSQL or DCOracle for Oracle.
Under the covers, almost all of these modules are implemented at least
partially in C, using the DB vendor's C libraries for accessing the DB.
In a similar way, a database "supports" JDBC when they ship a bunch of
.class files that implement the JDBC classes for their DB. Now, if your DB
only has a JDBC driver/library and no C-level access, it may be impossible
to write a DB module for that DB for Python. From Jython, of course, you
can simply use the JDBC driver.
Like I said, if you *really* want to avoid Java, you might try compiling
your Jython code to Java .class files and running that code under something
like Tomcat. Of course, then you'll need to learn a bit about how servlets
work.
---Tom
More information about the Python-list
mailing list