pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedHow to change the encoding inside the JDBC interface
7+ messages / 3 participants
[nested] [flat]
* How to change the encoding inside the JDBC interface
@ 2000-11-26 09:30 Dave <fubjj@flashmail.com>
0 siblings, 1 reply; 7+ messages in thread
From: Dave @ 2000-11-26 09:30 UTC (permalink / raw)
To: pgsql-interfaces
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
^ permalink raw reply [nested|flat] 7+ messages in thread
* RE: How to change the encoding inside the JDBC inter face
@ 2000-11-28 08:15 Peter Mount <petermount@maidstone.gov.uk>
0 siblings, 1 reply; 7+ messages in thread
From: Peter Mount @ 2000-11-28 08:15 UTC (permalink / raw)
To: 'fubjj@flashmail.com' <fubjj@flashmail.com>; pgsql-interfaces
There is in the CVS source some new encoding support which you may want to
try.
Peter
--
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
-----Original Message-----
From: Dave [mailto:fubjj@flashmail.com]
Sent: Sunday, November 26, 2000 9:31 AM
To: pgsql-interfaces@postgresql.org
Subject: [INTERFACES] How to change the encoding inside the JDBC
interface
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
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: How to change the encoding inside the JDBC inter face
@ 2000-11-28 08:38 Dave <fubjj@flashmail.com>
parent: Peter Mount <petermount@maidstone.gov.uk>
0 siblings, 0 replies; 7+ messages in thread
From: Dave @ 2000-11-28 08:38 UTC (permalink / raw)
To: Peter Mount <petermount@maidstone.gov.uk>; pgsql-interfaces
Yes, I've been search something like it for a week. Frankly, I've
been CVS too, but I don't which one to download. Could you please
help?
Thanks
Dave
On Tue, 28 Nov 2000 08:15:25 -0000, you wroth:
>There is in the CVS source some new encoding support which you may want to
>try.
>
>Peter
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: How to change the encoding inside the JDBC interface
@ 2000-11-28 09:56 George Koras <gkoras@cres.gr>
parent: Dave <fubjj@flashmail.com>
0 siblings, 0 replies; 7+ messages in thread
From: George Koras @ 2000-11-28 09:56 UTC (permalink / raw)
To: fubjj@flashmail.com; +Cc: pgsql-interfaces
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(); }
(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.
I'm worried about possible side effects this could have (although I
haven't seen any so far).
^ permalink raw reply [nested|flat] 7+ messages in thread
* RE: How to change the encoding inside the JDBC inter face
@ 2000-11-28 10:25 Peter Mount <petermount@maidstone.gov.uk>
0 siblings, 0 replies; 7+ messages in thread
From: Peter Mount @ 2000-11-28 10:25 UTC (permalink / raw)
To: 'fubjj@flashmail.com' <fubjj@flashmail.com>; Peter Mount <petermount@maidstone.gov.uk>; pgsql-interfaces
I only fetch the current beta one...
Peter
--
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
-----Original Message-----
From: Dave [mailto:fubjj@flashmail.com]
Sent: Tuesday, November 28, 2000 8:39 AM
To: Peter Mount; pgsql-interfaces@postgresql.org
Subject: Re: [INTERFACES] How to change the encoding inside the JDBC
inter face
Yes, I've been search something like it for a week. Frankly, I've
been CVS too, but I don't which one to download. Could you please
help?
Thanks
Dave
On Tue, 28 Nov 2000 08:15:25 -0000, you wroth:
>There is in the CVS source some new encoding support which you may want to
>try.
>
>Peter
^ permalink raw reply [nested|flat] 7+ messages in thread
* RE: How to change the encoding inside the JDBC inter face
@ 2000-11-28 11:18 Peter Mount <petermount@maidstone.gov.uk>
0 siblings, 1 reply; 7+ messages in thread
From: Peter Mount @ 2000-11-28 11:18 UTC (permalink / raw)
To: 'George Koras' <gkoras@cres.gr>; fubjj@flashmail.com; +Cc: 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
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: How to change the encoding inside the JDBC interface
@ 2000-11-28 11:54 George Koras <gkoras@cres.gr>
parent: Peter Mount <petermount@maidstone.gov.uk>
0 siblings, 0 replies; 7+ messages in thread
From: George Koras @ 2000-11-28 11:54 UTC (permalink / raw)
To: Peter Mount <petermount@maidstone.gov.uk>; +Cc: fubjj@flashmail.com; pgsql-interfaces
Peter Mount wrote:
> 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?
It seems to be the most elegant way to do it. And yes, a connection-specific
encoding could be useful.
Attachments:
gkoras.vcf (text/x-vcard, 282B) download
begin:vcard
n:Koras;George
x-mozilla-html:FALSE
org:Center for Renewable Energy Sources;Division for Energy Information Systems, Dissemination, and Training
adr:;;19th km, Marathonos ave.;Pikermi;;GR-15669;Greece
version:2.1
email;internet:gkoras@cres.gr
fn:George Koras
end:vcard
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2000-11-28 11:54 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-11-26 09:30 How to change the encoding inside the JDBC interface Dave <fubjj@flashmail.com>
2000-11-28 09:56 ` George Koras <gkoras@cres.gr>
2000-11-28 08:15 RE: How to change the encoding inside the JDBC inter face Peter Mount <petermount@maidstone.gov.uk>
2000-11-28 08:38 ` Re: How to change the encoding inside the JDBC inter face Dave <fubjj@flashmail.com>
2000-11-28 10:25 RE: How to change the encoding inside the JDBC inter face Peter Mount <petermount@maidstone.gov.uk>
2000-11-28 11:18 RE: How to change the encoding inside the JDBC inter face Peter Mount <petermount@maidstone.gov.uk>
2000-11-28 11:54 ` George Koras <gkoras@cres.gr>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox