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

From: Emi Lu <emilu(at)encs(dot)concordia(dot)ca>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: JDBC to load UTF8@psql to latin1@mysql
Date: 2012-12-14 14:06:44
Message-ID: 50CB3274.2080303@encs.concordia.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>> Yeah, I agree this is the right answer here, since you're using JDBC. By
>> the time you get a String from the MySQL driver, it's already in Java's
>> 2-bytes-per-char format. And the Postgres driver will deal with the
>> encoding on the output side. So the code I provided won't help you. I'm
>> afraid I don't know about Mybatis, but if it's built on JDBC I'd think
>> you've just got a configuration problem with what encoding the client
>> expects at either end.
> From: Tom lane
> I was wondering if the problem wasn't lots simpler than that. Is the
> character the OP is trying to convert actually part of LATIN1?

First, the data loading is from psql(unix) to mysql(Unix). Second, DB
transactions are through JAVA+MyBatis.

Steps:
(1) Read utf8(dot)data(at)psql from psql.xml into java.ArrayList<Bean>

(2) For each list.rec, save into mysql(at)latin through mysql.xml

Tried "jdbc:mysql://.../mysql_db?...unicode...encoding...=ISO..." No.
This does not work.

For now, through the following method, all letters are correctly
transformed except "È".

What does OP stand for?

Emi
--
public static String utf8_to_latin1(String str)
throws Exception
{
try
{
if(str.indexOf("È")>=0)
{
str = str.replaceAll("È", "E");
}
byte[] convertStringToByte = str.getBytes("UTF-8");
str = new String(convertStringToByte, "ISO-8859-1");
return str;
}catch(Exception e)
{
log.error("utf8_to_latin1 Error: " + e.getMessage());
log.error(e);
throw e;
}
}

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2012-12-14 14:21:44 Re: XML Schema for PostgreSQL database
Previous Message Yamen LA 2012-12-14 13:52:49 Re: Monitoring streaming replication from standby on Windows