以前作一個項目,用的是Mysql數據庫,後來想把數據庫換爲SQL Server,下面介紹換的方法。sql
數據庫: 用戶表: id(自增加) username(惟一) password;數據庫
MySql建庫語句:ide
create table users( id int(5) not null auto_increment, username varchar(20) not null, password varchar(20) not null, PRIMARY KEY (`id`), unique key(`username`) );
SqlServer建庫語句:spa
create table tb_users( id int not null identity(1,1) , username varchar(20) not null unique, password varchar(20) not null, constraint pkid primary key (id) );
當數據庫爲MySQL時,hibernate.cfg.xml核心配置以下:hibernate
Users.hbm.xml文件核心內容以下:code
當咱們把數據庫改成SQLServer時,hibernate.cfb.xml改成:xml
對應的Users.hbm.xml也要修改:rem
到這裏就修改好了,程序中基本上不用修改任何代碼。it