My DB2 database is using UTF-8 encoding. The source table has one colum with UTF-8 text like these lines below
Greek: Μπορώ να φάω σπασμένα γυαλιά χωρίς να πάθω τίποτα
Czech: Mohu jíst sklo, neublíží mi
Serbian: Ја могу да једем стакло
My java code is doing this (.. snipped out irrelevant parts.. )
ResultSet rs = stmt.executeQuery("SELECT SAMPLE_TEXT FROM UNICODE_TEST");
File file = new File("Unicode.txt");
BufferedWriter outFile = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),"UTF8"));
while (rs.next()) {
outFile.write(rs.getString("SAMPLE_TEXT"));
outFile.write( "\n" );
}
The result in my file don’t look like those in the source table at all.
I get this instead
Greek: ΜποÏÏŽ να φάω σπασμÎνα γυαλιά χωÏίς να πάθω τίποτα
Czech : Mohu jÃst sklo, neublÞà mi
Serbian: Ја могу да једем Ñтакло
What did I miss?
Your Java code is ok. Are you sure you your file content is wrong? What you see can appear wrong if you have your terminal wrong, for example. Can you see ok other text files in that computer encoded as UTF-8? (If you are unsure, read it in hexa, get a dump with
od, etc). If you are sure this is not your problem, then I’d point to some charset encoding setting in the JDBC connection (no experience with DB2).