Showing posts with label encoding. Show all posts
Showing posts with label encoding. Show all posts

Tuesday, March 20, 2007

MySQL encoding problem

This problem is very common and solution for it can be found very easily. But when I faced it, it was not so easy to find appropriate solution for me. So, I have MySQL db. I saved there data (for instance, strings) written in Russian (or Ukrainian). But when I wanted to view data (through MySQL console or browser in my web application) there were only ???????? (question marks). I tested all posted solutions in Internet (to change my.ini, to change sql script), but none helped. My founded solution was simply to set char set while creating db. For example :
CREATE DATABASE DEFAULT CHARSET=utf8;
USE ;
SET NAMES utf8;

Encoding problem with tomcat

Recently I had problem with encoding. Now I'm going to describe it. I created simple html template which used russian (or ukrainian) letters. Saved this template in UTF-8 encoding. When I view this template file in firefox or IE everything was written good. But when I wrapped it into war and put it into tomcat/webapp directory and tried to view it like localhost:8080/domain/site, I could not read a word. Firefox or IE also showed that current encoding is UTF-8. Changing of all encodings didn't help. The solution for current problem was to add option to JAVA_OPTS in catalina.bat (or catalina.sh in Linux) like -Dfile.encoding=UTF-8.