Re: Encoding from CopyManager.copyIn() - Mailing list pgsql-jdbc

From Kris Jurka
Subject Re: Encoding from CopyManager.copyIn()
Date
Msg-id alpine.BSO.2.00.0907221538320.17424@leary.csoft.net
Whole thread Raw
In response to Encoding from CopyManager.copyIn()  (Markus Kickmaier <markus.kickmaier@apus.co.at>)
List 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


pgsql-jdbc by date:

Previous
From: Markus Kickmaier
Date:
Subject: Encoding from CopyManager.copyIn()
Next
From: Ondřej Fafejta
Date:
Subject: COPY SELECT with parameters