Today when using Java to write to the database, we find that the INSERT statement and UPDATE statement after the execution, the database in Chinese display is "?? , after a review, the key question is whether the encoding format is uniform.
When creating a table, the format of each keyword is set to uniform, where I set the UTF8
Then you will find that in the database, the execution of SQL statements, will not be garbled, but in the use of Java calls, will be garbled, in fact, the reason is that, in connection with the database, we need to define the encoding format, we see the code is understood, when the encoding format is unified for UTF8 time, There will be no garbled characters.
1 class.forname ("Com.mysql.jdbc.Driver"2 //mydatabase is the database name, _test is the table name. There are three fields in the _test table: ID name author publish3 con = drivermanager.getconnection ("Jdbc:mysql://localhost : 3306/mydatabase?characterencoding=utf8 "," root "," 123456 ");
Where the encoding format is set to {? Characterencoding=utf8} this sentence.
(Another is the import data when the garbled phenomenon occurred, the solution is as follows:)
MySQL in the default database encoding set is not utf-8, so in the import data table when there is a Chinese error, this time to create a new own database, choose the encoding format for UTF8, sorting set is selected Utf8-unicode, and then import the data can be.
Reference: http://www.cnblogs.com/time-is-life/p/5901868.html
Modify the default character set: Http://www.cnblogs.com/xingyunblog/p/3836299.html
(for reference study only)
Solve the problem of inserting garbled characters in MySQL