为什么一切都这样? http://cs621724.vk.me/v621724427/19ade/rqgKgpzZPbU.jpg
create table b(tt varchar(2));
insert into b select 'ы ';
SELECT * FROM allservices.b;
Workbench的结果是 #tt 'ы' 但是用jdbc ......
connection = initConnection();
statement = connection.prepareCall("select tt from b where tt like '%ы%'");
resultSet = statement.executeQuery();
System.out.println("----------");
while (resultSet.next()) {
System.out.println(resultSet.getString("tt"));
}
System.out.println("==========");
statement = connection.prepareCall("select tt from b where tt like '%'");
resultSet = statement.executeQuery();
System.out.println("----------");
while (resultSet.next()) {
System.out.println(resultSet.getString("tt"));
}
System.out.println("==========");
结果是: ---------- ========== ---------- ы ==========
答案 0 :(得分:1)
set names utf8; -- To say your client is using utf8 encoding
create table b(tt varchar(2) CHARACTER SET utf8); -- to say the column is utf8
插入后,请执行以下操作:
mysql> select hex(tt) from b;
+---------+
| hex(tt) |
+---------+
| D18B20 | -- You should see this. D18B is the yery ('ы') character; 20 is space.
+---------+