Skip site navigation (1) Skip section navigation (2)

Re: Encoding from CopyManager.copyIn()

From: Kris Jurka <books(at)ejurka(dot)com>
To: Markus Kickmaier <markus(dot)kickmaier(at)apus(dot)co(dot)at>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Encoding from CopyManager.copyIn()
Date: 2009-07-22 19:41:10
Message-ID: alpine.BSO.2.00.0907221538320.17424@leary.csoft.net (view raw or flat)
Thread:
Lists: pgsql-jdbc

On Wed, 22 Jul 2009, Markus Kickmaier wrote:

> I'm using the copyIn() function of the CopyManager. It works fine until 
> I don't use an "umlaut" like ?. Then i get an PSQLException:
>
> org.postgresql.util.PSQLException: ERROR: invalid byte sequence for 
> encoding "UTF8": 0xfc
>
> My code looks like follows:
>
> ByteArrayOutputStream output = new ByteArrayOutputStream();
> PrintWriter writer = new PrintWriter(output);
> writer.println("abc???");
> writer.flush();
> ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
> long result = ((PGConnection) con_).getCopyAPI().copyIn(statement, input);

You should be using the copyIn(String, Reader) function rather than 
InputStream.  That way the CopyManager can encode the provide data to 
the database in the encoding it requires.

If using the InputStream method, you need to provide the data in UTF-8 
encoding.

Kris Jurka


In response to

pgsql-jdbc by date

Next:From: Ondřej FafejtaDate: 2009-07-23 08:49:12
Subject: COPY SELECT with parameters
Previous:From: Markus KickmaierDate: 2009-07-22 16:30:25
Subject: Encoding from CopyManager.copyIn()

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group