在MyEclipse环境下向Mysql数据库插入数据出现乱码问号,于是做了如下设置:
MyEclipse字符编码已经设为utf-8(window->preference...设置),MySQL的my.ini下设为default-character-set=utf8,hibernate.cfg.xml下jdbc:mysql://localhost:3306/users?useUnicode=true&characterEncoding=utf-8
这是就插入不了数据了,为什么啊?
先保存,在插入数据在上转,你知不知道
应该是编码问题,先试试跟字母之类的这些简单的字符看看能不能存储
试试:hibernate.cfg.xml下
jdbc:mysql://localhost:3306/users?useUnicode=true&characterEncoding=utf-8
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Hibernate: insert into student (name, age, sex) values (?, ?, ?)
使用过滤器
EncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
EncodingFilter
/*
差不多就可以了
my.ini default-character-set=utf8 设置的新建数据库默认的字符编码,你再看看你自己的数据库的字符编码是什么。再不行用navicat插入条utf8编码的数据试试就知道了