Web project storage data to database, Chinese garbled, resolution process

Source: Internet
Author: User

Troubleshooting reasons:

Break point, to see whether it is in the execution of the database operation before the garbled, or after the database operation is garbled.

Solutions for the former:

In Web. XML, add:

<Filter>   <Filter-name>Encodingfilter</Filter-name>   <Filter-class>Org.springframework.web.filter.CharacterEncodingFilter</Filter-class>   <async-supported>True</async-supported>   <Init-param:>      <Param-name>Encoding</Param-name>      <Param-value>UTF-8</Param-value>   </Init-param></Filter><filter-mapping>   <Filter-name>Encodingfilter</Filter-name>   <Url-pattern>/*</Url-pattern></filter-mapping>
When configuring the JDBC data source, add:
Jdbc:mysql://127.0.0.1:3306/logistics?useunicode=true&amp;characterencoding=utf-8
Storage database operation garbled, solution:
Log in to the database and execute the following sql:

Show variables like ' character% ';

Results:

| character_set_client | UTF8 |

| character_set_connection | UTF8 |

| Character_set_database | Latin1 |

| Character_set_filesystem | binary |

| Character_set_results | UTF8 |

| Character_set_server | Latin1 |

| character_set_system | UTF8 |

Indicates that the Character_set_database,character_set_server encoding format was incorrect when installing the database.

Solve:

Locate the my.cnf file under the MySQL installation path and add the following two lines under [mysqld]:

Character_set_server=utf8
init_connect= ' SET NAMES UTF8 '

Check again for problem resolution:

| character_set_client | UTF8 |

| character_set_connection | UTF8 |

| Character_set_database | UTF8 |

| Character_set_filesystem | binary |

| Character_set_results | UTF8 |

| Character_set_server | UTF8 |

| Character_set_system | Utf8

Web project storage data to database, Chinese garbled, resolution process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.