X-Original-To: pgsql-jdbc-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 429639FA5E6 for ; Sun, 18 Jun 2006 05:26:20 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 60517-03 for ; Sun, 18 Jun 2006 05:26:14 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [131.203.101.226]) by postgresql.org (Postfix) with ESMTP id 03DB69F9AD3 for ; Sun, 18 Jun 2006 05:26:12 -0300 (ADT) Received: from 221x253x225x162.ap221.ftth.ucom.ne.jp ([221.253.225.162] helo=[192.168.1.171]) by yass.opencloud.co.nz with asmtp (TLS-1.0:DHE_RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1Frsbi-0003kt-Vw; Sun, 18 Jun 2006 20:26:11 +1200 Message-ID: <44950E11.90508@opencloud.com> Date: Sun, 18 Jun 2006 17:25:53 +0900 From: Oliver Jowett User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) MIME-Version: 1.0 To: Yair Zas CC: pgsql-jdbc@postgresql.org Subject: Re: A question about postgresql 8.1 and UTF strings References: <23adfcc00606180110g43045926o2badbc5aee77a2d3@mail.gmail.com> In-Reply-To: <23adfcc00606180110g43045926o2badbc5aee77a2d3@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/43 X-Sequence-Number: 15323 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