I have web app in jsf2.0 on tomcat 6 and MySQL. I’m using special characters for example “ąśżźć”. I’m able to read data from MySQL and show it properly on the web page. The problem occurs when user is filling in the form with any special character then in MySQL the characters are replaced to ‘?’. But if I use MySQL Workbench tool and I’ll make insert to DB everything works and the special characters are showed proper on the web page.
My Configuration:
JSF - UTF-8 (for response and request character encoding)
MySQL columns are configured to use UTF-8, example: DESCRIPTION varchar(100) CHARACTER SET utf8 null
character_set_client utf8
character_set_connection utf8
character_set_database latin1
character_set_filesystem binary
character_set_results utf8
character_set_server latin1
character_set_system utf8
And the character_set_server = latin1 makes me big problems.
When it is UTF-8 everything is ok, in latin1 not.
My hosting company will not change the MySQL setting so the latin1 stays :-(.
How can I make workaround for that?
I tried already many solutions like creating filter, makes conversion using Charset and String.getBytes(). I’m running out of ideas.
For connecting I’m using JDBC by org.apache.tomcat.jdbc.pool.DataSource.
MySQL JDBC driver uses by default the platform default character encoding as obtained by
Charset#getDefaultCharset()which is not necessarily UTF-8. You need to set it as a parameter in the JDBC URL:See also: