The thing with the euro sign

Yesterday, Kabuto asked in the IRC whether someone is using UTF-8 for the MySQL databases and if they experienced some problems with the euro sign. Yes, I use UTF-8 and I also store the euro sign in my database, and I assumed it works for me. But that was an illusion, the euro sign was shown as a question mark as I did a query. A sign of an encoding problem…

Since it worked when I entered the euro sign in my application, the problem had to be in my sql scripts or in my ant script I use to execute the sql scripts. The sql scripts were ok, as they worked when executed via MySQL Query Browser. So the problem had to be in my ant script. But what was the cause of the problem? After searching for a long time I found the problem: I have to specify the encoding in the URL used by JDBC. Instead of

jdbc:mysql://localhost/mydb

I have to use

jdbc:mysql://localhost/mydb?characterEncoding=UTF-8

Oh, I really love this entire encoding stuff ;-)

3 Comments

  1. RosSoft
    Posted February 6, 2006 at 2:29 pm | Permalink

    Working with CakePHP and UTF8, I have a problem with encoding. With this SQL sentence I resolved it:

    SET NAMES ‘utf8’;

  2. Posted May 3, 2006 at 1:16 am | Permalink

    Hey thanks – i’ve been in charset hell for some time trying to support a multilingual site.. i first tried latin1_bin til i realised it made searches case sensitive, so i tried latin1_general_ci and ended up with a problem with the € symbol, then i moved to utf-8 and STILL had this problem. Thanks to a quick google i came accross your blog and this sorted it. Hopefully my character set headaches will soon be long gone!

  3. Posted May 3, 2006 at 10:48 am | Permalink

    @elliot: I am glad to hear that this post was useful for you!


%d bloggers like this: