aspose file tools*
The moose likes Java in General and the fly likes Java reading from utf-8 MySql problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java reading from utf-8 MySql problem" Watch "Java reading from utf-8 MySql problem" New topic
Author

Java reading from utf-8 MySql problem

Ernest Gungl
Greenhorn

Joined: Feb 21, 2009
Posts: 5
Hello friends!

Well, I have a problem with reading from MySql database (db). I use MySQL version: 5.5.20, mysql-connector-java-5.1.14-bin.jar and jre6. I start MySql server with: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci (utf-8 representation in MySql).

Eveything, I write from Java application into MySql database works O.K. I can see our special national characters in database excatly as I wrote (or as I would write) them directly in the phpmyadmin (databse editor written in php).

The only problem is that I can't read special national characters from database. I see some graphical symbols instead of my desired national characters. Java uses UTF-16 character representation, but MySql in my case uses utf-8. So, I can belive, that "mysql-connector-java-5.1.14-bin.jar" correctly converts from utf-16 to utf-8 automaticly (so here I talk about writing to database). I DON'T KNOW, WHY THIS CONVERSION (utf-8 in MySql -> utf-16 in java) DOESN'T WORK IN THE OPPOSITE DIRECTION (JAVA READING FROM DATABASE)? Well, reading from Java it doesn't work also when I write my special national characters directly in databse (so I can see my national characters in datbase correctly) through MySql database editor phpmyadmin.

Any suggestion?

best regards,
Ernest

[Edit: removed excessive use of bold and uppercase]
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

How do you display the data after reading them from the database? There certainly is a possibility they are correctly read, but your font cannot properly display them. Also Windows consoles are notoriously known to be unable to display various encoding correctly.

I'd suggest to write the data obtained from the database into a file (making sure the encoding of the output file is properly set) and inspecting the contents of the file, to verify that the data are actually being read wrongly from the database.
Ernest Gungl
Greenhorn

Joined: Feb 21, 2009
Posts: 5

Hello Mr. Martin

After reading from database I display message as follows:




I will try with file as you've suggested.

Thank you for reply,
Ernest
Ernest Gungl
Greenhorn

Joined: Feb 21, 2009
Posts: 5
Hello again!

I've tried your idea about writing to file. It works O.K.

Thank you and best regards,
Ernest
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java reading from utf-8 MySql problem