2

I have a stand alone java program that opens a text file in UTF-8 mode and read each line in the file containing Swedish characters like å, ä, ö. The text file has been saved in utf-8 mode. The java program prints what it reads from the file into standard output and I have verified that the program can read and print these special characters properly. The program then saves this data it read from the file into a Mysql 5.5 database with default utf-8 collation by using a JDBC connection.

Nevertheless, when the program inserts these textual data with the Swedish characters into the mysql database, the special characters are replaced with weird black characters that are not readable. If I change the database collation to latin1 instead, then all these special characters are removed by the MySQL server. I have googled the issue and found suggestions involving the use variations of utf-8 and latin1 as the default database collation but non of them seems to have helped me so far.

I wonder if there is anyone facing a similar issue on placing Swedish characters in a mysql database? If so, could you tell me what is the collation type and charset I should be using to have swedish charecters correctly in the database. Do I have to make a specific setting in JDBC database connection for these letters to be saved correctly? Perhaps the issue is more java related but I verified visually that my java program can read/print these characters properly. Thanks.

F. Aydemir
  • 2,665
  • 5
  • 40
  • 60
  • Can you set encoding when establishing the db connection? – Yoggi Jan 25 '13 at 14:17
  • Maybe this is helpful: http://stackoverflow.com/questions/3040597/jdbc-character-encoding – Yoggi Jan 25 '13 at 14:18
  • Utf-8 should work fine, I normally use utf-8 general with swedish letters, no problem. Be sure to use the same encoding everywhere. – Yoggi Jan 25 '13 at 14:23
  • I have added the charecter encoding type as specified in the example in the above link but there is no improvement... – F. Aydemir Jan 25 '13 at 19:46

0 Answers0