"MySQL" MySQL database handles Chinese character transfer in servlet

Source: Internet
Author: User

Many MySQL default encoding is latin1, if MySQL in the installation time did not change the code, directly to its input in Chinese is not possible, will be garbled,

First, the encoding of the field to be stored in Chinese is changed from Latin1 to Utf-8. If you use Mysqlquerybrowser to open the table you want to modify, click the field you want to modify, and modify it to utf-8 in column charset of column details.

In the servlet Java file, the connection database must be connected with a parameter? useunicode=true&characterencoding=utf8&useoldaliasmetadatabehavior=true

At the same time, servlets use form forms to pass Chinese characters between JSP Web pages and Java files, which can be garbled.

If you are experiencing garbled characters, first use <%@ page import= "java.net.*" in the header of the Web page%>

Then in the Chinese form, the string is transcoded into Utf-8 by Urlencoder.encode ("string", "Utf-8").

Then, in a Java file that needs to be received using Request.getparameter, use Urldecoder.decode (Request.getparameter ("string defined parameter name"), "Utf-8"); decode

In this way, into the database of Chinese characters, there will be no garbled situation.

For a database that is in the process of debugging, you can use TRUNCATE table to empty the entire table, and most importantly, to zero the value of the self-increment field.

Truncate is a SQL syntax that can quickly erase all data in a table. It can also do the function of counting reset zero recalculation for fields with automatic increment.

"MySQL" MySQL database handles Chinese character transfer in servlet

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.