Solve MySql garbled Problem

Source: Internet
Author: User


The MySql garbled problem solves a series of problems caused by the garbled code and cannot be avoided during the real-recorded development process. Garbled characters are the cause of character sets. They generally do not have much to do with the logic. That is to say, there is no problem in the overall direction of the system. A vulnerability occurs in a small place, which causes the program to fail to run normally, so Garbled text is a very disgusting thing. Here, we will briefly introduce the garbled problem we have encountered, the ideas in the process of solving the problem, and the general operations. What we need to learn is how to analyze the problem and solve the problem, the difference between "fish" and "fish" is not just to solve the current difficulties again and again based on the operations on the Internet. Background of www.2cto.com: the function to be implemented is simple. You can use dom4J to read XML files and then use Spring and Hibernate to write data to the MySql database (multiple tables, of course, the whole process is completed at one time by Spring control transactions, and rollback is performed with exceptions. Symptom: an error is reported when half of data is written to the database. The general error message is that the record is not unique. Analysis and operation: Check your code and use HibernateTemplete in Spring to save the data. There should be no problem. Observe again: it seems to be a problem with foreign key constraints, because every time data is inserted into a table with foreign keys, it cannot be input. Analysis and operation: since it is a foreign key table problem, we should first determine what the content in the foreign key table is, so manually change the database isolation level to view the data, which is indeed garbled! Q: How do I access the database with garbled characters? Analysis and operation: It is garbled when reading xml, or when writing data to the database. Breakpoint debugging again to test whether the code is garbled in the program. Symptom: No garbled characters are printed out in eclipse. Analysis and operation: This shows that there is no problem in the program and it is a database problem. So first change the database link string to specify the encoding, then change the database encoding, and then breakpoint debugging again. Symptom: the database is still garbled, but the garbled form is changed. It was all "?". It's a mess of text. Analysis and operation: it is obvious that the above series of operations to modify the encoding format work, but they are not modified. Check the encoding formats again and find no problems ...... For help: It is too difficult to use the command window. Use a third-party client, so use a third-party client. The strange thing is that the client shows no problem! Analysis and operation: if the client has no problem with the command window, it indicates that the database is not garbled, and garbled code may be displayed on the command line. Set the command line display characters, and the display is normal! Test data import again ---- everything is OK. Thinking and Conclusion: phenomenon: in fact, this problem was solved when the encoding was modified for the first time, however, since the program was not executed during breakpoint debugging, the database is still garbled. Conclusion: The program should be completed during each debugging, And the Context Environment of the error should be simulated, instead of focusing only on the error itself. Symptom: XML encoding, dom4j reading encoding, database encoding, database connection string encoding, and command line window display encoding are involved here. Which of the above cannot solve the problem (I am not aware of the last one ). To sum up, the concept of concept refers to grasping each control variable, from the beginning to the end, consciously jumping out of the environment to make assumptions.

Related Article

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.