In this blog I will show you how I have configured Unicode in Spring Hibernate and MySQL project where we are using JSP for the client side.
First the data source bean configuration needs to be modified as follows:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>com.mysql.jdbc.Driver</value> </property> <property name="url"> <value>jdbc:mysql://localhost:3306/db_name?autoReconnect=true&useUnicode=true amp;characterEncoding=UTF-8</value> </property> <property name="username"> <value>root</value> </property> <property name="password"> <value>root</value> </property> </bean>
Second, you need to create/alter table and set collation to UTF-8.
These are the 2 steps which I have done but faced few problems:
With this option set now I can see UTF-8 data represented like this in database
Solution is to add the following line in the head section
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> Or <meta charset="UTF-8"/>
Nothing more needs to be done with request and response; only with above configuration changes utf-8 data can be stored and retrieved from the database. I spent almost half a day to figure out the problem and finally got it working. Hope this will help you to configure Unicode with other databases as well. Good Luck. :)