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