Modify MySQL database, data table, field encoding (solve JSP garbled)

Source: Internet
Author: User
Tags character set modify mysql one table mysql database phpmyadmin
js|mysql| Code | solution | data | database

To solve JSP garbled, first of all to understand the JSP garbled reason

1. Install the server installed MySQL will let you choose a code, if this code and your Web page is inconsistent, may cause JSP page garbled
2. Creating a database in a phpMyAdmin or Mysql-front system allows you to choose an encoding that, if not inconsistent with your Web page, may create a JSP page garbled
3. Creating a table allows you to choose an encoding, if this encoding is inconsistent with your Web page code, may also cause the JSP page garbled
4. Add a field when creating a table can choose to encode, if this encoding and your Web page encoding inconsistent, may also cause JSP page garbled
5. The user submits the JSP page the code and displays the data the JSP page code to be inconsistent, will certainly cause the JSP page garbled.
such as user input data jsp page is BIG5 code, display user input JSP page is gb2312, this 100% will cause JSP page garbled
6. Incorrect Character set
To note:
1. The text you see on some websites may have several encodings, if you see a traditional characters, it may be BIG5 encoding, it may be utf-8 encoded, more likely to be GB code, yes, that is, there are simplified traditional Chinese characters, there is also a simplified Chinese code, we must understand this point.
If you are making a simplified coded web page, code for GB2312, if there are Hong Kong and Taiwan's visitors to submit traditional information, it may cause garbled, the solution is (1) the site code set to Utf-8, which can be compatible with all the world's characters, (2) If the site has been operating for a long time, There are many old data, you can no longer change the Simplified Chinese settings, it is recommended to set the page encoding to GBK,
The difference between GBK and GB2312 is: GBK can display more characters than GB2312, to show the traditional characters of simplified code, you can only use GBK
7.JSP connection MySQL DATABASE statement specified incorrect encoding
8.JSP page does not specify the encoding of data submission, will cause garbled:

Therefore, the reason for JSP garbled is nothing more than several, know the reason, to solve the JSP garbled method is also easier
We express:
1. If the code that installs MySQL is not changed, many friends are buying a virtual host to build a website, Do not have the right to change the MySQL installation code, which we can skip, because as long as the next step is correct, the same can solve the garbled problem
2. Modify the database encoding, if the database encoding is incorrect: You can execute the following command in phpMyAdmin: ALTER database ' test ' DEFAULT CHARACTER set UTF8 COLLATE utf8_bin
The above command sets the encoding of the test database to UTF8
3. To modify the encoding of the table: Alter TABLE ' category ' DEFAULT CHAR Acter SET UTF8 COLLATE utf8_bin
The above command is to change the encoding of one table category to UTF8
4. Modify the encoding of the field:
ALTER TABLE ' test ' change ' dd ' DD ' VARC HAR (s) CHARACTER SET UTF8 COLLATE utf8_bin not NULL
The above command is to change the field encoding of DD in the test table to UTF8
5. If this is easy to solve, just check the page and modify the source files of Cha RSet can be
,//This right is no problem
6. This situation is also modified page charset,
7. In the statement that the JSP connects to the database,
private String url= "jdbc:mysql:// localhost/"+db_name+" user= "+login_name+" &password= "+login_password+" &CHARACTERENCODING=GBK "; The phase key depends on the characterencoding
8. This garbled situation, just add request.setcharacterencoding at the beginning of the page ("GBK");

Note: In accordance with the above method changes can only ensure that your new inserted data will not garbled, for example: If your user has submitted the data is BIG5, but you want to change the above method can be used in the GB2312 of the page is not possible, this text within the code transformation can only be solved by a separate program, Please web745.com other related articles


Summary: First of all to judge the JSP garbled is inserted into the database after the garbled, or JSP page just submitted to the garbled, if the JSP just received a page of the data display on the garbled, it is definitely the character set is wrong, but the person did not add request.setcharacterencoding ("GBK" );

If it's a database, refer to the 2,3,4 method above

It could be a coding problem.
So connect the database to see
Jdbc:mysql://localhost:3306/xxxx Useunicode=true&characterencoding=utf-8
See if it works.



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.