This article references from: http://blog.csdn.net/wangchangshuai0010/article/details/12714575Java.sql.SQLException:Incorrect string value: ' \xe6\x88\x91\xe7\x9a\x84 ... ' for column ' GroupName '
Today, using MySQL to write data to MySQL in a Java program, the following error occurred:
Java.sql.SQLException:Incorrect string value: ' \xe6\x88\x91\xe7\x9a\x84 ... ' for column ' GroupName ' at row 1
Very tangled, I thought it should be one of the following:
(1). Data encoding setting error when creating database
(2). Data encoding Setup error when connecting to database
for (1), I delete the original database, re-create a new database when setting the encoding, my settings are as follows:
Character Set:utf8--UTF-8 Unicode
Collation:utf8_general_ci
For example:
Create DATABASE myuser default character set UTF8 collate utf8_general_ci;
After discovering this setting, this problem cannot be resolved.
for (2), I write the connection statement as:
"jdbc:mysql://" + IP + ": 3306/users? Useunicode=true&characterencoding=utf8"
But the problem is still unresolved.
I also carefully observed the program I wrote, found in the program to create a table in the database operation, the following statement:
"CREATE TABLE Friendslist (QQ varchar (7) Primary Key,remark varchar (), groupName varchar (20));"
In this way, the problem becomes clear, the original creation of each table must set the data encoding method, the following statement:
"CREATE TABLE Friendslist (QQ varchar (7) Primary Key,remark varchar (), groupName varchar) charset UTF8 collate u tf8_general_ci; "
To summarize, there are several reasons why the title of this article has the following problems:
(1). Data encoding setting error when creating database
CREATE DATABASE myuser default character set UTF8 collate utf8_general_ci;
(2). Data encoding Setup error when connecting to database
"jdbc:mysql://" + IP + ": 3306/users?useunicode=true&characterencoding=utf8"
(3). Data encoding settings error when creating a table
"CREATE TABLE Friendslist (QQ varchar (7) Primary Key,remark varchar (), groupName varchar) charset UTF8 collate utf8_ General_ci; "
MVC design pattern for user Registration form submission to database Chinese garbled problem