Writing weird unicode characters into mysql

Recently, I had to import a database of foreign names into MySQL. The names were written in farsi, like this شرکت ملی صنایع پتروشیمی (don’t ask me what that means, I have no idea)

Once imported into Mysql, it looked something like this “???? ?????????? ?? ???”. That’s bad. That’s MySQL saying it can’t recognize the characters.

So first, I made sure my table column could handle this character set. I changed the table column’s encoding to “UTF-8”. But this wasn’t enough.

Next I had to change the jdbc connection string from

jdbc:mysql://localhost/myDatabase

to

jdbc:mysql://localhost/myDatabase?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8

And that should do it

Advertisements
Tagged , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: