Re: JDBC to load UTF8@psql to latin1@mysql

From: Emi Lu <emilu(at)encs(dot)concordia(dot)ca>
To: Paul Jungwirth <pj(at)illuminatedcomputing(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: JDBC to load UTF8@psql to latin1@mysql
Date: 2012-12-13 14:06:42
Message-ID: 50C9E0F2.4000308@encs.concordia.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> I don't think your Java code does what you think it does. You should
> read some more about how Java handles string encodings. Here is a method
> I wrote some years ago that might also help you. It converts streams,
> not strings, but what you need should be pretty close (and simpler):
> /**
> * Interprets in according to encIn, and converts it to encOut,
> * writing to out. Allocates buffer for the buffer size.
> * @param encIn The input encoding.
> * @param encOut The output encoding.
> * @param in The data to convert.
> * @param out Where to send the converted data.
> * @param buffer The size of the buffer or 0 for the default.
> * @throws IOException
> */
> public void run(String encIn, String encOut, InputStream in,
> OutputStream out, int buffer) throws IOException {
> Reader r = null;
> Writer w = null;
> int len;
> char[] b;
> try {
> if (buffer > 0) {
> r = new BufferedReader(new InputStreamReader(in, encIn), buffer);
> w = new BufferedWriter(new OutputStreamWriter(out, encOut),
> buffer);
> } else {
> r = new BufferedReader(new InputStreamReader(in, encIn));
> w = new BufferedWriter(new OutputStreamWriter(out, encOut));
> buffer = DEFAULT_BUFFER_SIZE;
> }
> b = new char[buffer];
>
> while ((len = r.read(b, 0, buffer)) != -1) {
> w.write(b, 0, len);
> }
> } finally {
> try {
> if (r != null) r.close();
> } finally {
> if (w != null) w.close();
> }
> }
> }
> Btw, none of this has anything to do with Postgres. :-)
Thank you for the code first. I will try it later. The problem I had as
mentioned in the subject is:
(1) psql(at)utf8
(2) mysql(at)latin1

When I load data from (1) to (2) through Mybatis, french characters
could not be mapped correctly in (2). I was thinking that psql may have
methods could help this. But it seems that I have to try from java
coding side :-(

--
Emi

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Markus 2012-12-13 15:14:25 Re: How to keep the last row of a data set?
Previous Message Edson Richter 2012-12-13 14:05:06 Re: JDBC to load UTF8@psql to latin1@mysql