Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 23137B5DC29 for ; Sat, 29 Oct 2011 03:35:50 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 90020-08 for ; Sat, 29 Oct 2011 06:35:43 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from outbound.vnet-inc.com (outbound.vnet-inc.com [216.146.104.103]) by mail.postgresql.org (Postfix) with ESMTP id BCEC0B5DC27 for ; Sat, 29 Oct 2011 03:35:43 -0300 (ADT) Received: from [192.168.157.132] (unknown [76.75.27.41]) by outbound.vnet-inc.com (Postfix) with ESMTP id DEBBE5865 for ; Sat, 29 Oct 2011 00:35:46 -0600 (MDT) Message-ID: <4EAB9D85.2030707@ttc-cmc.net> Date: Sat, 29 Oct 2011 00:30:29 -0600 From: dmp User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.13) Gecko/20100914 SeaMonkey/2.0.8 MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Re: JDBC driver is too fussy about Unicode Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201110/79 X-Sequence-Number: 22332 James Pharaoh wrote: > The test case works for me, and also on the server. A little > investigation shows one big difference, the code I am using is somehow > using a JDBC2 statement class, whereas adding some output to the test > case when it runs successfully shows me using a JDBC4 one. > > Furthermore, the app in question has a page where I can enter queries > in groovy. Trying a similar testcase there also works, but I am > getting a JDBC3 statement class. > > I have a feeling this might be a big part of the problem but don't > really know enough about what is going on underneath to be sure. I am > using Hibernate 3.3.2 which is a little old. > > I wonder if it is somehow managing to force the driver to use JDBC2? > How would you write a testcase to do this? > > Does the JDBC driver for PostgreSQL contain compatibility code for > JDBC2 and could it be that there is a bug there? > > Of course, I could try and upgrade Hibernate as well. I'll look into > that but the last time I had to do that it didn't work out so well. > > Thanks, > James > > 2011/10/29 Oliver Jowett: >> On 29 October 2011 13:17, Oliver Jowett wrote: >> >>> Can't reproduce it here; the attached testcase works fine for me >> >> Oops, testcase really attached this time. >> >> Oliver Oliver's test case on my setup fails in the insert because the database indicates the character 0xf09f9480 of encoding "UTF8" has no equivalent in "LATIN1". The original error given is thrown in the class indicated but the only thing really going on there is a new String creation with the encoding derived from the connection. What I would like to see is what that encoding is for Oliver's sucessful test case and then again on the app if possible. Not sure right now how to do that, but I would say that encoding is not being returned the same through the app. with hibernate as when the JDBC is ran directly. The only other thing maybe is the encodedString returned. See below: danap Abstractjdbc2ResultSet.getString() { ~ ~ Encoding encoding = connection.getEncoding(); try { return trimString(columnIndex, encoding.decode(this_row[columnIndex - 1])); } catch (IOException ioe) { throw new PSQLException(GT.tr("Invalid character data was found. This is most likely caused by stored data containing characters that are invalid for the character set the database was created in. The most common example of this is storing 8bit data in a SQL_ASCII database."), PSQLState.DATA_ERROR, ioe); } From Encoding: public String decode(byte[] encodedString) throws IOException { return decode(encodedString, 0, encodedString.length); } public String decode(byte[] encodedString, int offset, int length) throws IOException { if (encoding == null) return new String(encodedString, offset, length); --------> return new String(encodedString, offset, length, encoding); }