After some work, I can deal with the problem. Below is the code that works for me to enable JDBC working with UTF8
<bean id="DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="com.mysql.jdbc.Driver" /> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=UTF-8" /> <property name="maxPoolSize" value="10" /> <property name="maxStatements" value="0" /> <property name="minPoolSize" value="5" /> </bean>
Using useUnicode=true&characterEncoding=UTF-8 with & served the purpose
To be able to use the same with Hibernate, also specify the following sleep mode properties
<property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">false</prop> <prop key="hibernate.connection.useUnicode">true</prop> <prop key="hibernate.connection.characterEncoding">UTF-8</prop> <prop key="hibernate.connection.charSet">UTF-8</prop> </props> </property>
Specify the request encoding format in the filter
public class ApplicationFilter implements Filter { public void destroy() { } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { request.setCharacterEncoding("utf-8"); } public void init(FilterConfig fConfig) throws ServletException { } }
Now, even if your application and db do not support special characters, check the database character set, try to recreate the database and use charset UTF8 instead of latin1
Nitin source share