The thing with the euro sign

Published on January 31, 2006 and tagged with ant  cakephp  jdbc  mysql  problem  tip

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 ;-)

7 comments baked

  • RosSoft February 06, 2006 at 14:29

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

    SET NAMES ‘utf8′;

  • elliot May 03, 2006 at 01:16

    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!

  • cakebaker May 03, 2006 at 10:48

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

  • Richard van den Tol February 14, 2007 at 23:35

    It took me many hours to get €-sign (Euro) displayed in AJAX application. Solution: Start PHP program with next line:
    header(“Content-Type:text/html; charset=iso-8859-1″);

  • cakebaker February 15, 2007 at 10:55

    @Richard: Thanks for this hint!

  • Gustav May 29, 2008 at 07:40

    Haha, you’re lucky that’s the only char that’s not in your charset :-)
    I’m from Sweden and need to fix this for every app I’m working with…

    The Swedish chars that fuck things up: åäöÅÄÖ

  • cakebaker May 29, 2008 at 17:37

    @Gustav: In German we have similar special chars: äöüÄÖÜ, but fortunately most apps are in English ;-)

Bake a comment




(for code please use <code>...</code> [no escaping necessary])

© daniel hofstetter. Licensed under a Creative Commons License