Character encoding issues with MySQL and JAVA

August 12, 2010

I had an interesting (annoying) bug with one of my Java applications today. Using the MySQLConnector I was reading a record out of a table, then re-inserting it with a few fields changed. One of the untouched fields was a piece of text into which a user had used a non-standard character (a greek sigma σ). The JAVA appeared to read the original record fine and would print it out correctly to the terminal. However, writing it back the db caused it to be converted into a question mark (?). Tracked the problem down to the MySQL driver not being able to determine the character set of the database and making a guess which was wrong. You can specify the character set in the connection string like this though which fixes the problem:


There is a whole list of cool flags you can put on the end of the connection string listed here:

My other favourite is profileSQL=true which prints all the statements sent to the MySQL db to the terminal.


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: