在几天做开发的时候使用到了数据库。一个可坑爹的问题就是乱码啦!在安装数据库的使用选中了utf8编码在jsp中使用utf8来获取数据库中的显示的时候老是出现乱码怎么解决这个问题呢?
我们在安装Mysql数据库的使用指定了编码utf8有时候这个指定也许不会起作用,这个时候我们得去Mysql的安装目录中去到 my.ini文件打开如下:
[client]
port=3306
[mysql]
default-character-set=gbk
//上面一句是指定客户端访问数据库使用的编码,这里在安装的时候可能没有被修改,修改之
# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[mysqld]
# The TCP/IP Port the MySQL Server will listen on
port=3306
#Path to installation directory. All paths are usually resolved relative to this.
basedir="E:/MySQL/MySQL Server 5.0/"
#Path to the database root
datadir="E:/MySQL/MySQL Server 5.0/Data/"
# The default character set that will be used when a new schema or table is
# created and no character set is defined
default-character-set=utf8
//上面一句指定在数据库中用什么编码来储存数据,为了通用最底层数据储存使用utf8来储存数据
好了修改了上面我们得去重新启动服务.....
接下来我们得把以前的数据删除、因为我们现在修改编码不会影响以前写入的数据、所有删除之
搞定.......