From: Oliver Jowett <oliver@opencloud.com>
To: Yair Zas <yair.zaslavsky@gmail.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: A question about postgresql 8.1 and UTF strings
Date: Sun, 18 Jun 2006 17:25:53 +0900
Message-ID: <44950E11.90508@opencloud.com> (raw)
In-Reply-To: <23adfcc00606180110g43045926o2badbc5aee77a2d3@mail.gmail.com>
References: <23adfcc00606180110g43045926o2badbc5aee77a2d3@mail.gmail.com>
Yair Zas wrote:
> System.out.println(user.getBytes().length) - however, instead of seeing
> 8 bytes (2 bytes per each character, 4 characters ), i saw 4 bytes ....
> Can you please tell me what is it that I'm doing wrong?
getBytes() uses the JVM's default encoding to translate the String to
bytes.. This is usually something like ISO-8859-1, which is a
one-byte-per-character encoding that can't represent Hebrew letters.
If you want to generate a representation in a particular encoding (e.g.
your description implies you're expecting a particular
2-byte-per-character encoding) then you should use the getBytes()
variant that takes an encoding name.
This is not something specific to JDBC, it's standard Java. If you are
working with characters beyond 7-bit US-ASCII, I'd strongly recommend
doing some research into Java's internal string representation and how
that is transformed into bytes .. The javadoc for Charset is one
starting point:
http://java.sun.com/j2se/1.4.2/docs/api/java/nio/charset/Charset.html
-O
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: oliver@opencloud.com, yair.zaslavsky@gmail.com
Subject: Re: A question about postgresql 8.1 and UTF strings
In-Reply-To: <44950E11.90508@opencloud.com>
References: <23adfcc00606180110g43045926o2badbc5aee77a2d3@mail.gmail.com> <44950E11.90508@opencloud.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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