kefet
kefet

Reputation: 741

why mysql does not recognize Unicode characters on its LONGTEXT dataype?

I have a database mysql database with

mysql>SHOW VARIABLES LIKE "%version%";

+-------------------------+-------------------------+
| Variable_name           | Value                   |
+-------------------------+-------------------------+
| innodb_version          | 5.5.31                  |
| protocol_version        | 10                      |
| slave_type_conversions  |                         |
| version                 | 5.5.31-0ubuntu0.12.10.1 |
| version_comment         | (Ubuntu)                |
| version_compile_machine | x86_64                  |
| version_compile_os      | debian-linux-gnu        |
+-------------------------+-------------------------+

and

mysql> show variables like 'character%';

+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | utf8                       |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

when I insert a non Latin language on varchar it works fine yet when I try to insert on LONGTEXT type it shows me "??????"

how can I can fix this.

I"m using java, hibernate jsf 2.0. Spring framework.

Upvotes: 0

Views: 1036

Answers (2)

kefet
kefet

Reputation: 741

I didn't mention earlier that I have also Sring frame work. the solution was to add this filter on my web.xml. hope this help for other people.

enter code here


<filter>
<filter-name>encoding-filter</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>
 </filter>
 <filter-mapping>
 <filter-name>encoding-filter</filter-name>
 <url-pattern>/*</url-pattern>
 </filter-mapping>

Upvotes: 0

Ihor Kharchenko
Ihor Kharchenko

Reputation: 11

Try to run this query after you init connection to db:

SET NAMES UTF8

Upvotes: 1

Related Questions