-----------------------------------------------------------
Mysql5.0 + myeclipse4.1 + tomcat5.0 all use the default encoding method
1: insert data to MySQL:
Add the encoding method of this page to the page
<% @ Page contenttype = "text/html; charset = gb2312" %>
Change the Chinese text you want to insert from gb2312 to iso-8859
Title = new string (title. getbytes ("gb2312"), "ISO-8859-1 ");
* ** Do not add any encoding method to the URL of the database on this page *****
Conn = java. SQL. drivermanager. getconnection ("JDBC: mysql: // localhost/zqswork", "root", "root ");
2: read data from MySQL to the page:
The encoding method is still added to the page.
<% @ Page contenttype = "text/html; charset = gb2312" %>
Change the Chinese you want to read from iso-8859 to gb2312
<% Username = new string (username. getbytes ("ISO-8859-1"), "gb2312"); %>
* *** Note that this page must be encoded in the Database URL (opposite to the preceding )******
Conn = java. SQL. drivermanager. getconnection ("JDBC: mysql: // localhost/zqswork? Useunicode = true & characterencoding = gb2312 "," root "," root ");
Note the following three points: 1. When creating a database: Create Database 'database' Character Set 'utf8' Collate 'utf8 _ general_ci '; 2. Create Table 'database _ user '( 'Id' varchar (40) not null default '',
'Userid' varchar (40) not null default '',
) Engine = InnoDB default charset = utf8;3. JDBC: mysql: // localhost: 3306/database? Seunicode = true & characterencoding = UTF-8 After these three settings are complete, there will basically be no problems. |
| |
It is caused by character set problems. You can use show full fields from + Table name to see the encoding format of your column.
Change it to GBK or gb2312 uTF-8.
If not, change the encoding format of your table to the above encoding format. I have changed both of them.
OK!
Restart MySQL first.
Run the following command at the command prompt:
Net stop MySQL
Net start MySQL
Yes, the encoding problem is very strange. I have a table with two fields of the same type and an OK one, but data too long. Then I exported the SQL statement and changed it.
------------------------------
-- Table structure for Cities
------------------------------
Create Table 'cities '(
......
.....
) Engine = InnoDB default charset = utf8; // you can change it to utf8.
I have encountered such a problem and spent a long time solving it. I have summarized it and hope it will be useful to you.
MySQL error: Data truncation: data too long for column: this problem is caused by the character set encoding format problem. modify my. INI file. Under [MySQL], change default-character-set = utf8 to UTF-8 or GBK, this file also contains the # created and no character set is define Under default-character-set = utf8 and then find the corresponding database file in the data directory to find the DB. opt file default-character-set = utf8
Default-collation = utf8_swedish_ci both lines of text must be modified. If not, check the encoding of your table and the encoding format of fields in the table: right-click a table on the table and choose "Table message"> "DDL" to view the encoding format of the table and field. If the format is different from that in the configuration file, modify the format as follows: right-click the table-design table-options-Character Set, and click each string field in your table to check whether the character set encoding below is consistent. All the work is done.
For example, set all codes to utf8, And the contenttype = "text/html; charset = UTF-8" of JSP"
Alter database 'test' default Character Set utf8 collate utf8_bin
Alter table 'category' default ......
Chinese character garbled problem:
(1) modify my. ini to set default-character-set = GBK (Note: there are two points)
(2) modify the database. Opt configuration file default-character-set = GBK default-collation = gbk_chinese_ci under the corresponding database directory in the Data Directory
(3) When generating databases, tables, and fields, do not implicitly include Latin.
Check. If it is Latin, change it to GBK.
In this way, you should pay attention to Character Set setting at three levels. There should be no problem.
The problem I encountered is that Chinese characters can be inserted in the program, but it will not be displayed normally when I view it in the database!
However, when SQL is used in MySQL Doc to insert Chinese characters, the error message "data too long" is reported. I am using utf8 encoding!
Before inserting data, I unified the encoding, all of which were UTF-8.
1. the URL of the connection data is
JDBC: MySQL :/// 127.0.0.1: 3306/dbname? Useunicode = true & characterencoding = utf8
2. When installing mysql5.0, The utf8 encoding format is used.
3. Change the database attribute encoding to utf8.
First, check the variable encoding: Show variables like 'character _ SET _ % ';
Set names utf8 using this statement; // This will basically change most of the encoding, and there may be one left. That doesn't matter!
However, if you insert Chinese characters using SQL statements in MySQL Doc, the error of data too long will still be reported,
This is because in the MySQL console attributes, the default code page contains two types of encoding: Simplified Chinese GBK and
OEM in the United States, we generally use GBK by default, so this causes an error when inserting it under the doc!
I can only try to use a program to insert data, but I think you are using GBK, so it should be fine. You only need to unify the encoding,
In addition to using GBK, encoding is added when you create a database or table.
4. Create Database dbname default Character Set utf8;
5. Create Table tabname (...) engine = InnoDB default charset = utf8;
I hope it will be useful to you. I will try again. There is no other way!
(1) Modify c: \ developer \ mysql5.0 \ My. ini (MySQL server instance configuration file)
Set default-character-set = GBK (Note: there are 2 places)
(2) modify the DB. Opt configuration file under the corresponding database directory in the Data Directory
Default-character-set = GBK
Default-collation = gbk_chinese_ci
Restart MySQL.
In fact, encoding is still a problem. The main problem lies in the following:
1. Database encoding format
2. encoding format of the language used
3. If the encoding format is submitted or received by the webpage
If the encoding formats of the preceding three points are consistent, no garbled characters will occur.