[Mysql] the Mysql database processes Chinese characters transmitted in Servlet.
The default encoding of many Mysql instances is latin1. If Mysql does not change the encoding during installation, it cannot be entered into Chinese directly and garbled,
First, change the encoding of the field to be stored in Chinese from latin1 to UTF-8. If MySQLQueryBrowser is used, you can open the table to be modified, click the field to be modified, and modify it to UTF-8 in Column Charset of Column details.
In the Servlet Java file, must the database be connected with parameters? UseUnicode = true & characterEncoding = utf8 & useOldAliasMetadataBehavior = true
At the same time, Servlet may use form forms to pass Chinese characters between jsp pages and java files, which may also contain garbled characters.
In case of garbled characters, use <% @ page import = "java.net. *" %>
Then, in the form of passing Chinese characters, the string is transcoded to UTF-8 through URLEncoder. encode ("string", "UTF-8 ").
Then, in the Java file that needs to be received using request. getParameter, use URLDecoder. decode (request. getParameter ("parameter name defined by string"), "UTF-8"); decode
In this way, no garbled characters will be transmitted into the database.
For databases during the debugging process, you can use Truncate Table to clear the entire Table. The most important thing is that the auto-increment field value can be set to zero.
Truncate is an SQL syntax that can quickly clear all data in a data table. In addition, it can reset the count to zero and re-calculate the fields with auto-increment values.