ubuntu12下hibernate3.3 和mysql 5连接中文乱码解决

来源:互联网 发布:余文乐潮牌淘宝有店吗 编辑:程序博客网 时间:2024/06/01 08:43

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.如下图

终于可以在地址里面出现中文


原创粉丝点击