Hi Jython people!
As part of my work with Django, I'm facing some problems with data
type conversions from Django to JDBC. As we know, DB-API doesn't
enforces the client code to specify the parameters type. JDBC has
different expectations here, working better when types are specified,
althought we have setObject() which let the driver figure out the
correct type. Problem is, we can't know in advance how good drivers
will be at that.
On the zxJDBC side, the execute() method allows an extra parameter to
specify JDBC Field Types. If the extra parameter is not provided, it
limits itself to call __tojava__ on each parameter. That would still
work for basic types such as ints, doubles, floats, strings, unicodes
and None. Things get interesting with:
a) booleans, because they map to Integer by default (!). Then, the
JDBC Driver or the database may reject that (as PostgresSQL does )
b) longs, because they map to BigInteger, which may not be
automatically mapped by the JDBC Driver (in fact, PostgreSQL don't).
c) date, time, datetime: They are implemented in python, so
__tojava__ returns "this", which is a PyObjectDerived instance.
We could solve (a) changing PyBoolean#__tojava__. Is there any strong
reason for the current behaviour?
I'm going to fix (b) on the PostgreSQLDataHandler.
For (c) I'm proposing to add a "__tojava__" stub to *Derived objects,
to let classes implemented in python to define __tojava__ and convert
itself to Java instances. Then, I would map date, time and datetime to
java.sql.Date, java.sql.Time and java.sql.Timestamp. Does that sounds
Now, if someone else has experienced problems with type conversions
and zxJDBC (people porting other CPython webapp frameworks, maybe?) it
would be good to know, so we can tackle as much problems as we can at
the same time. Obviously, I'd like to hear other people ideas on the
Leo Soto M.