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