MySQL works in Latin1 - how to insert UTF-8 encoded data?

I have a web application in jsf2.0 on tomcat 6 and MySQL. I use special characters like "śżźśżźć". I can read data from MySQL and display it on a web page. The problem occurs when the user fills out a form with any special character and then in MySQL the characters are replaced with "?". But if I use MySQL Workbench tool and I do a DB paste, everything works and special characters show up on the web page.

My config:

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 character_set_server = latin1 creates big problems. When it's UTF-8 everything is fine, in latin1 it is not.

My hosting company will not change the MySQL setting, so latin1 remains: - (.

How can I do a workaround for this?

I have tried many solutions already, such as creating a filter, converting using Charset and String.getBytes (). I'm running out of ideas.

To connect, I use JDBC at org.apache.tomcat.jdbc.pool.DataSource.

+3


source to share


1 answer


The MySQL JDBC driver defaults to using the platform's default character encoding obtained with Charset#getDefaultCharset()

, which is not necessarily UTF-8. You have to set it as a parameter to the JDBC url:

jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=UTF-8

      



See also:

+8


source







All Articles