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: (view raw, whole thread or download thread mbox)
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 

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-2017 The PostgreSQL Global Development Group