Make UTF-8 available to host arabic data in Mysql DB using Spring
Hello everyone, I want to put arabic data with my code into mysql database in my webApp:
the technologies i used: Spring MVC / Hibernate:
its my code in my logical Busines part:
transaction.setExplaination("Something with Arabic alphabet");
..
..
getHibernateTemplate().saveOrUpdate(transaction);
when i get the explanation for my transaction and display it in the .jsp page it was shown as ?????? and his problem.
in mvc-dispatcher-servlet.xml:
at first i used it:
<bean id="driverManagerDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/DB_Name?useUnicode=true&characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value="myjava123"/>
</bean>
but this throws an error for my xml, so i delete it.
I used org.springframework.web.filter.CharacterEncodingFilter in my web.xml:
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
but also no difference in results
I would be grateful if someone could show me how it works.
source to share
The error you were getting in your XML is most likely caused by the use of '&' which is not a legal object in XML. You should definitely encode the connection, so the working connection url should be something like
<property name="url" value="jdbc:mysql://localhost:3306/DB_Name?useUnicode=true&characterEncoding=UTF-8"/>
You can also make sure your server is configured correctly, for tomcat, for example by adding URIEncoding to the connector
<connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8"/>
will indicate the character encoding used to decode the URI. You should find the equivalent for your server
source to share