Jython Data Extraction problem

Diez B. Roggisch deets at nospam.web.de
Thu Mar 8 04:39:29 EST 2007


Steve Williams wrote:

> The data is an 8-byte 2s complement binary integer stored in a MSSQL
> 2005 CHAR column.  (COBOL did that, not me). I'm using zxJDBC to read
> the data and Jython to process.
> I could extract the integer if it wasn't returned in the resultset as
> unicode.  Things like ord(char) and struct.unpack('>B',char) to get at
> the bits don't seem to work.  struct.unpack('>g',string) is not available.
> I've tried fooling with charset in the url and the connect statement and
> tried encode, but I have no experience here.
> Is there anyway to get Jython/zxJDBC to stop converting the string to
> unicode?
> Any advice is welcome.

It's a JDBC-thing in the end, see if you find a solution there. Apart from
that, I don't see the problem really - why can't you just create a
byte-string by using the .encode-method? Sure, you need to know which
encoding was actually used when reading the bytes from the DB. But you
should be able to figure that out, there aren't too much candidates -
basically the usual suspects of cp1250, latin1 and the like.

Diez



More information about the Python-list mailing list