0

I have one database with encoding of Windows Baltic(windows-1257). I copy the data to other database with encoding UTF-8 Lithuanian (using sql language). After copying data, I still don't get UTF-8 values - "Nerûdijantis plienas" and I need "Nerūdijantis plienas". And I made little Java application, witch should take data from UTF-8 db with data copied from Latin db and System.out.println(..). But now since data is still wrong after copying i get wrong encoding printed out. What should I do? Should i copy data with some kind of encoding sentences or should i use Java to change encoding during printing out?

EDIT:I need something like iconv in PHP, it works when I use it to convert data.

Minutis
  • 1,193
  • 1
  • 17
  • 47
  • maybe there http://dba.stackexchange.com/questions is better place for simlair questions – mKorbel Dec 28 '11 at 12:08
  • You see, it's not that I would like to change encoding of the data. If it's possible, I would like only in java to convert String from ISO-8859-1 to UTF-8 encoding on printing it out. – Minutis Dec 28 '11 at 12:12
  • I still think that why convert in/output from/to JDBC , let's Sql Engine returns correct chars, btw you can flag your own question with ask for moving to dba.stackexchange.com/questions forum, – mKorbel Dec 28 '11 at 12:37

4 Answers4

1

maybe help you to use MySql Collations,

mKorbel
  • 109,525
  • 20
  • 134
  • 319
0

To convert ISO-8859-1 to UTF-8 we can use following code

//convert ISO-8859-1 to UTF-8

byte[] utf8 = new String(dataInString, "ISO-8859-1").getBytes("UTF-8");

or have a look on java.nio.Charset

see Converting UTF-8 to ISO-8859-1 in Java - how to keep it as single byte

Community
  • 1
  • 1
Sunil Kumar Sahoo
  • 53,011
  • 55
  • 178
  • 243
0

Of course in the database the text should be in UTF-8. You can do a mysqldump just of one concerned table to check where it is going wrong.

A nice programmer's editor like JEdit (http://jedit.org) can switch encodings, which may help.

A web server would need to do response.setContentText("text/html; charset=UTF-8"). A normal application should have no problem, as Unicode is used internally by Java, and the operating system encoding is that of Lithuanian: System.getProperty("file.encoding").

For the Java MySQL driver you will need to set the communication to UTF-8 too: Character encoding issue with linux and mysql

System.out.println prints in the default system encoding, which might be misleading. Best is a hex dump of the bytes, so you can actual check.

Community
  • 1
  • 1
Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • It's not web service. As for communication, it is set and doesn't work. JEdit if I understand, you suggest to dump my DB and switch dump.sql file encoding to UTF-8? If so, it doesn't help. If I switch, characters remain like they was. – Minutis Dec 29 '11 at 07:41
0

I flagged this thread as needed to move to different forum, but since nothing was made, I got it working here.

Community
  • 1
  • 1
Minutis
  • 1,193
  • 1
  • 17
  • 47