刚学完jdbc:
现在做个小项目练习一下
项目:旅馆定房系统
项目分析: 业务逻辑:Roombiz(房间的添加,删除,修改,查找)
数据:Room(房间的数据,如,唯一id号,房间号)
问题:我在oracle数据库中建立room房间表,把id设置为主键,并且自动生成,保证唯一就行了,可是老师还用很很多其他的方法来创建id,为什么呢?
Room类:
package linshi.hbs.entity;
public class Room
{
private int id;
private String no;
private String type;
private String description;
public String getDescription()
{
return description;
}
public void setDescription(String description)
{
this.description = description;
}
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public String getNo()
{
return no;
}
public void setNo(String no)
{
this.no = no;
}
public String getType()
{
return type;
}
public void setType(String type)
{
this.type = type;
}
}
Roombiz类: 注意就看添加方法
package linshi.hbs.biz;
import java.util.Collection;
import linshi.hbs.entity.Room;
import linshi.hbs.util.IdGenerator;
import linshi.hbs.util.IdGeneratorFactory;
public class RoomBiz
{
public void add(Room room) throws Exception
{
IdGenerator generator = IdGeneratorFactory.getIdGenerator();
generator.setProperty( "sequence ", "room_seq ");
room.setId(generator.nextId());
}
public void modify(Room room) throws Exception
{
}
public void remove(Room room) throws Exception