RE: How to change the encoding inside the JDBC inter face

From: Peter Mount <petermount(at)maidstone(dot)gov(dot)uk>
To: "'George Koras'" <gkoras(at)cres(dot)gr>, fubjj(at)flashmail(dot)com
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: RE: How to change the encoding inside the JDBC inter face
Date: 2000-11-28 11:18:42
Message-ID: 1B3D5E532D18D311861A00600865478CF1B5D3@exchange1.nt.maidstone.gov.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

> -----Original Message-----
> From: George Koras [mailto:gkoras(at)cres(dot)gr]
> Sent: Tuesday, November 28, 2000 9:56 AM
> To: fubjj(at)flashmail(dot)com
> Cc: pgsql-interfaces(at)postgresql(dot)org
> Subject: Re: [INTERFACES] How to change the encoding inside
> the JDBC interface
>
>
> Dave wrote:
>
> > Hi all,
> >
> > I have a database which is EUC_TW encoded, but I would like to use
> > Big5 to encode my data. I've tried serveral ways to program my
> > program, i.e. using string(in_bytestr, "BIG5") to convert my data.
> > However, the interface just use EUC_TW to store my data anyhow.
> >
> > Any experience can share with me?
> >
> > Thanks
> > Dave
>
> I had a very similar problem. I don't know if this will be of any help
> to Dave but I would like people in this list to see what I did and
> comment on any possible side effects.
>
> No matter what I did I could not correctly send an ISO8859_7 encoded
> query to the database. The query would reach the servlet OK, but when
> passed to the JDBC driver it would change to ISO8859_1.
>
> Now, at least according to this:
>
> http://www.jguru.com/jguru/faq/view.jsp?EID=78088
>
> the JDBC driver should communicate with the database using
> the encoding
> suggested by the file.encoding property. However the driver
> was clearly
> ignoring my changing file.encoding. So, after a bit of reverse
> engineering, I came up with this solution:
>
> I opened the driver source code (file Connection.java,
> function ExecSQL,
> line 296) and replaced the following line:
>
> buf = sql.getBytes();
>
> with the lines:
>
> String enc = System.getProperty("file.encoding");
> try { buf = sql.getBytes(enc); }
> catch (UnsupportedEncodingException e) { buf = sql.getBytes(); }

This is similar to the encoding patch

> (buf is the byte array containing the query, which immediately after
> that is sent to the database). So now, just before the query is passed
> by the driver to PostgreSQL, it is converted to whatever is
> the default
> file.encoding and everything works just fine (after I changed
> file.encoding via my JRE's configuration files, of course). Moreover,
> according to the JDK manual, getBytes() should convert Strings to byte
> arrays according to the platform's default character encoding,
> therefore, the driver should behave as expected (using
> file.encoding to communicate with the database) and my hacking
> activities should not be needed. That's why I figured that the whole
> problem was a bug in my JDK (I use JDK1.2 in Redhat Linux running on a
> Digital Alpha machine). In fact, I never had any similar problems when
> my servlets were running under Windows.

That makes sense, but from the number of reports I've seen getBytes() must
be broken.

> I'm worried about possible side effects this could have (although I
> haven't seen any so far).

The encoding patch added a new method to Connection called getEncoding().
The sensitive parts of Connection then replace getBytes() with
getBytes(getEncoding()), with a new encoding argument to PG_Stream's
ReceiveString() method.

However, the encoding is only changed with the charSet connection property
(allows you to set the encoding on a per connection basis). Now I feel this
should default (if charSet is absent) to be the file.encoding property. What
do you think?

--
Peter Mount
Enterprise Support Officer, Maidstone Borough Council
Email: petermount(at)maidstone(dot)gov(dot)uk
WWW: http://www.maidstone.gov.uk
All views expressed within this email are not the views of Maidstone Borough
Council

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message George Koras 2000-11-28 11:54:12 Re: How to change the encoding inside the JDBC interface
Previous Message Peter Mount 2000-11-28 10:25:08 RE: How to change the encoding inside the JDBC inter face