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

Поиск
Список
Период
Сортировка
От Peter Mount
Тема RE: How to change the encoding inside the JDBC inter face
Дата
Msg-id 1B3D5E532D18D311861A00600865478CF1B5D3@exchange1.nt.maidstone.gov.uk
обсуждение исходный текст
Список pgsql-interfaces
> -----Original Message-----
> From: George Koras [mailto:gkoras@cres.gr]
> Sent: Tuesday, November 28, 2000 9:56 AM
> To: fubjj@flashmail.com
> Cc: pgsql-interfaces@postgresql.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@maidstone.gov.uk
WWW: http://www.maidstone.gov.uk
All views expressed within this email are not the views of Maidstone Borough
Council


В списке pgsql-interfaces по дате отправления:

Предыдущее
От: Peter Mount
Дата:
Сообщение: RE: How to change the encoding inside the JDBC inter face
Следующее
От: George Koras
Дата:
Сообщение: Re: How to change the encoding inside the JDBC interface