1.建立数据库时一定要用utf8,不然如何修改字符编码都徒劳
create database myhibernate2 default character set utf8;
create table customers(
id bigint not null primary key,
name varchar(15) not null,
email varchar(128) not null,
password varchar(8) not null,
phone int,
address varchar(255),
sex char(1),
is_married bit,
description text,
image blob,
birthday date,
registered_time timestamp
)default character set utf8 engine myisam;
2.修改hibernate.cfg.xml文件
将原来的连接后面加上编码,如下:
jdbc:mysql://localhost:3306/myhibernate2?useUnicode=true&characterEncoding=utf8
3.如下图
终于可以在地址里面出现中文