0 Replies Latest reply on Mar 23, 2017 6:56 PM by George tsobis

    Wildfly 10.1.0 with mysql on centos 6+ problem with connection encoding

    George tsobis Newbie

      Hello to all,

      I have an application that uses most of the java ee 7 (jsf, ejb, cdi, jms, jpa etc).

       

      The application is hosted on a wildfly 10.1.0 Final and connects to a mysql database through the following datasource.

       

      <datasource jta="true" jndi-name="java:/commerceDS" pool-name="commerceDS" enabled="true" use-ccm="true">
                          <connection-url>jdbc:mysql://localhost:3306/commerce</connection-url>
                          <driver-class>com.mysql.jdbc.Driver</driver-class>
                          <connection-property name="databaseName">
                              commerce
                          </connection-property>
                          <driver>MySqlJDBCDriver</driver>
                          <pool>
                              <min-pool-size>30</min-pool-size>
                              <initial-pool-size>50</initial-pool-size>
                              <max-pool-size>100</max-pool-size>
                              <prefill>true</prefill>
                          </pool>
                          <security>
                              <user-name>root</user-name>
                              <password>password</password>
                          </security>
                          <validation>
                              <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
                              <background-validation>true</background-validation>
                              <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
                          </validation>
                          <statement>
                              <share-prepared-statements>false</share-prepared-statements>
                          </statement>
                      </datasource>
      

       

      On a windows 10 machine it works ok, however, when tried to use a linux machine with centos 6+, although the data are persisted to the database, the encoding is wrong. For example I cannot persist or merge greek characters. On the other hand if I input data to the table from an sql editor like workbench, I can retrieve data within the application with the correct encoding.

       

      I tried using useUnicode=true&amp;characterEncoding=utf-8 on the datasource connection url but it does not work.

       

      <connection-url>jdbc:mysql://localhost:3306/commerce?useUnicode=true&amp;characterEncoding=utf-8</connection-url>
      

       

       

      Afterwards I saw in some examples the following useUnicode=true&amp;amp;characterEncoding=utf-8 and I had the same result.

       

      After testing every configuration I could think of, I tried to create a vm with centos and setup the same environment and had the same problem.

      To solve my problem I had to force mysql to use the utf8 in the my.cnf

       

      [mysqld]

      character-set-server=utf8

      collation-server=utf8_general_ci

       

      Am I doing something wrong or is this a bug?

       

      Finally, to point out the obvious I am sure that the data from the jsf form are received from the server with the correct encoding. I have tested writing the received data to the log as well as the faces message of the jsf and they are displayed correctly.

       

      Regards

      Tsobis George