我的mysql数据库状态如下:
--------------
D:Program FilesMySQLMySQL Server5.2binmysql.exe Ver 14.13 Distrib 5.2.0-f
alcon-alpha, for Win32 (ia32)
Connection id:
Current database:
Current user:
SSL:
Using delimiter:
Server version:
GPL)
Protocol version:
Connection:
Servercharacterset:
Db
Clientcharacterset:
Conn.characterset:
TCP port:
Uptime:
Threads: 1 Questions: 230 Slow queries: 0 Opens:25 Flush tables: 1 Open ta
bles: 1 Queries per second avg:%
--------------
无论我用jsp页面还是servlet(而且统一为utf-8)向数据库插入中文时出现乱码,显示为:???,在cmd界面插入中文数据时出现ERROR:1366(HY000)Incorrectstring value:,我google了很久,试了很多种方法都没用,只有一个地方说的方法有效。就是将MySQL Server5.2中的my.ini中的CLIENT SECTION部分中的default-character-set=utf-8改为default-character-set=GBK,其他的都不变,然后重新打开mysql的cmd界面执行插入操作就ok了。
没改之前的my.ini为:
# MySQL Server Instance ConfigurationFile
#----------------------------------------------------------------------
... ...
# CLIENT SECTION
#----------------------------------------------------------------------
#
# The following options will be read by MySQLclient applications.
# Note that only client applications shipped byMySQL are guaranteed
# to read this section. If you want your ownMySQL client program to
# honor these values, you need to specify it asan option during the
# MySQL client libraryinitialization.
#
[client]
port=3306
[mysql]
default-character-set=utf8
# SERVER SECTION
#----------------------------------------------------------------------
... ...
改了之后为:
# MySQL Server Instance ConfigurationFile
#----------------------------------------------------------------------
... ...
# CLIENT SECTION
#----------------------------------------------------------------------
#
# The following options will be read by MySQLclient applications.
# Note that only client applications shipped byMySQL are guaranteed
# to read this section. If you want your ownMySQL client program to
# honor these values, you need to specify it asan option during the
# MySQL client libraryinitialization.
#
[client]
port=3306
[mysql]
default-character-set=GBK
# SERVER SECTION
#----------------------------------------------------------------------
... ...
网络上很多高手都说要jsp、servlet、mysql的编码要统一,但是统一为utf-8却会出现问题,只有这样改了才ok,至于到底原因在还请高手们多多指教。