//把酒店的数据设计写在数据库中,然后再把数据库中的酒店Dao在eclipse中
//酒店数据设计图
– 创建房间表
CREATE TABLE room(
room_id INT PRIMARY KEY AUTO_INCREMENT, – 房间ID
room_name VARCHAR(50), – 房间名称
room_type VARCHAR(50), – 房间类型
room_price VARCHAR(50), – 房间价格
room_state VARCHAR(50) – 房间状态
);
– 创建客户表
CREATE TABLE CLIENT(
client_id INT PRIMARY KEY AUTO_INCREMENT, – 客户ID
client_name VARCHAR(100), – 客户名称
client_sex VARCHAR(10), – 客户性别
client_birthday VARCHAR(50), – 客户生日
client_phone VARCHAR(100) – 客户电话
);
– 创建部门表
CREATE TABLE department(
department_id INT PRIMARY KEY AUTO_INCREMENT, – 部门ID
department_name VARCHAR(100), – 部门名称
department_phone VARCHAR(100) – 部门电话
);
– 创建员工表
CREATE TABLE staff(
staff_id INT PRIMARY KEY AUTO_INCREMENT, – 员工ID
department_id INT, – 部门ID
staff_name VARCHAR(100), – 员工名称
staff_sex VARCHAR(10), – 员工性别
CONSTRAINT fk_department_id FOREIGN KEY (department_id) REFERENCES department(department_id) – 外键
);
– 创建酒店表
CREATE TABLE hotel(
hotel_id INT PRIMARY KEY AUTO_INCREMENT, – 酒店ID
hotel_name VARCHAR(100), – 酒店名称
hotel_address VARCHAR(200), – 酒店地址
hotel_type VARCHAR(100) – 酒店类型
);
– 创建订房表
CREATE TABLE reservation(
reservation_id INT PRIMARY KEY AUTO_INCREMENT, – 订房ID
room_id INT, – 房间ID
client_id INT, – 客户ID
staff_id INT, – 员工ID
reservation_time DATETIME, – 订房时间
reservation_amount INT, – 总金额
reservation_remark VARCHAR(400), – 备注
hotel_id INT, – 酒店ID
CONSTRAINT fk_room_id FOREIGN KEY(room_id) REFERENCES room(room_id), – 添加房间外键
CONSTRAINT fk_client_id FOREIGN KEY(client_id) REFERENCES CLIENT(client_id), – 添加客户外键
CONSTRAINT fk_staff_id FOREIGN KEY(staff_id) REFERENCES staff(staff_id), – 添加员工外键
CONSTRAINT fk_hotel_id FOREIGN KEY(hotel_id) REFERENCES hotel(hotel_id) – 添加酒店外键
);
DROP TABLE reservation;
DROP TABLE hotel;
DROP TABLE CLIENT;
DROP TABLE staff;
DROP TABLE department;
DROP TABLE room;
– 各表中插入你和你朋友的开房记录
INSERT INTO CLIENT VALUES(NULL,“张三”,“女”,“1999-01-01”,“15327276373”);
INSERT INTO CLIENT VALUES(NULL,“李四”,“女”,“1998-05-05”,“15457276373”);
INSERT INTO room VALUES(NULL,“8-13”,“双人间”,“180”,“已开”);
INSERT INTO hotel VALUES(NULL,‘华天大酒店’,‘芙蓉区110号’,‘豪华型’);
INSERT INTO reservation VALUES(NULL,1,1,1,‘2010-01-01’,300,“含早餐”,1);
INSERT INTO department VALUES(NULL,‘1322445554’,‘8599223’);
INSERT INTO staff VALUES(NULL,1,‘王五’,‘女’);
SELECT * FROM room;
– 查询2010-01-01这天,你在哪家酒店,那个房间住了,展示出所有的信息
SELECT h.hotel_name
,r.room_name
FROM reservation rt,hotel h,room r WHERE h.hotel_id
= rt.hotel_id
AND rt.room_id
= r.room_id
AND rt.reservation_time
=‘2010-01-01’;
– 查询客服MM小美为你开房的所有的记录.
SELECT rt.* FROM reservation rt,staff s,room r,CLIENT c,hotel h WHERE rt.hotel_id
= h.hotel_id
AND rt.room_id
= r.room_id
AND rt.client_id
= c.client_id
AND rt.staff_id
= s.staff_id
AND s.staff_sex
=‘女’;
– 查询2010年你开房的总金额
SELECT c.client_name
,SUM(rt.reservation_amount
) FROM reservation rt , CLIENT c WHERE
rt.client_id
= c.client_id
AND rt.reservation_time
>=‘2009-01-01’
AND rt.reservation_time
<‘2012-01-01’ AND c.client_name
=‘张三’;
– 查询你在哪个房间住的次数最多
SELECT COUNT(*),r.room_name
FROM reservation rt,room r,CLIENT c WHERE rt.room_id
= r.room_id
AND
rt.client_id
= c.client_id
AND r.room_name
= (SELECT MAX(rm.room_name
) FROM room rm) AND
c.client_name
=‘张三’ GROUP BY r.room_name
;
//酒店的模型
//房间
/**
*
*/
package com.yidu.model;
/**
- 描述:房间类
- @author zhouyuxian
- @date 2019年8月28日 下午5:48:44
- @version 1.0
*/
public class Room {
private Integer roomID;//房间ID
private String name;//房间名称
private String type;//房间类型
private String price;//房间类型
private String state;//房间状态
public Integer getRoomID() {
return roomID;
}
public void setRoomID(Integer roomID) {
this.roomID = roomID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
}
//客户
/**
*
*/
package com.yidu.model;
/**
- 描述:客户类
- @author zhouyuxian
- @date 2019年8月28日 下午7:10:12
- @version 1.0
*/
public class Client {
private Integer clientID;//客户ID
private String clientName;//客户姓名
private String clientSex;//客户性别
private String clientBirth;//客户生日
private String clientPhone;//客户电话
public Integer getClientID() {
return clientID;
}
public void setClientID(Integer clientID) {
this.clientID = clientID;
}
public String getClientName() {
return clientName;
}
public void setClientName(String clientName) {
this.clientName = clientName;
}
public String getClientSex() {
return clientSex;
}
public void setClientSex(String clientSex) {
this.clientSex = clientSex;
}
public String getClientBirth() {
return clientBirth;
}
public void setClientBirth(String clientBirth) {
this.clientBirth = clientBirth;
}
public String getClientPhone() {
return clientPhone;
}
public void setClientPhone(String clientPhone) {
this.clientPhone = clientPhone;
}
}
// 部门
/**
*
*/
package com.yidu.model;
/**
- 描述:部门表
- @author zhouyuxian
- @date 2019年8月28日 下午7:41:17
- @version 1.0
*/
public class Department {
private Integer dtID;//部门ID
private String dtName;//部门名称
private String dtPhone;//部门电话
public Integer getDtID() {
return dtID;
}
public void setDtID(Integer dtID) {
this.dtID = dtID;
}
public String getDtName() {
return dtName;
}
public void setDtName(String dtName) {
this.dtName = dtName;
}
public String getDtPhone() {
return dtPhone;
}
public void setDtPhone(String dtPhone) {
this.dtPhone = dtPhone;
}
}
//员工
/**
*
*/
package com.yidu.model;
/**
- 描述:员工表
- @author zhouyuxian
- @date 2019年8月28日 下午7:43:34
- @version 1.0
*/
public class Staff {
private Integer staffID;//员工ID
private Integer dtID;//部门ID
private String staffName;//员工名称
private String staffSex;//员工性别
public Integer getStaffID() {
return staffID;
}
public void setStaffID(Integer staffID) {
this.staffID = staffID;
}
public Integer getDtID() {
return dtID;
}
public void setDtID(Integer dtID) {
this.dtID = dtID;
}
public String getStaffName() {
return staffName;
}
public void setStaffName(String staffName) {
this.staffName = staffName;
}
public String getStaffSex() {
return staffSex;
}
public void setStaffSex(String staffSex) {
this.staffSex = staffSex;
}
}
//酒店
/**
*
*/
package com.yidu.model;
/**
- 描述:酒店类
- @author zhouyuxian
- @date 2019年8月28日 下午11:36:38
- @version 1.0
*/
public class Hotel {
private Integer hotelID;
private String hotelName;
private String hotelAddress;
private String hotelType;
public Integer getHotelID() {
return hotelID;
}
public void setHotelID(Integer hotelID) {
this.hotelID = hotelID;
}
public String getHotelName() {
return hotelName;
}
public void setHotelName(String hotelName) {
this.hotelName = hotelName;
}
public String getHotelAddress() {
return hotelAddress;
}
public void setHotelAddress(String hotelAddress) {
this.hotelAddress = hotelAddress;
}
public String getHotelType() {
return hotelType;
}
public void setHotelType(String hotelType) {
this.hotelType = hotelType;
}
}
//订房
/**
*
*/
package com.yidu.model;
import java.sql.Date;
/**
-
描述:订房表
-
@author zhouyuxian
-
@date 2019年8月28日 下午7:46:06
-
@version 1.0
*/
public class Reservation {
// reservation_remark VARCHAR(400),
private Integer rtID;//订房ID
private Integer roomID;//房间ID
private Integer clientID;//客户ID
private Integer staffID;//员工ID
private Date rtTime;//订房时间
private Integer rtAmount;//订房总金额
private String rtRemark;//备注
private Integer rtHotel;public Integer getRtHotel() {
return rtHotel;
}
public void setRtHotel(Integer rtHotel) {
this.rtHotel = rtHotel;
}
public Integer getRtID() {
return rtID;
}
public void setRtID(Integer rtID) {
this.rtID = rtID;
}
public Integer getRoomID() {
return roomID;
}
public void setRoomID(Integer roomID) {
this.roomID = roomID;
}
public Integer getClientID() {
return clientID;
}
public void setClientID(Integer clientID) {
this.clientID = clientID;
}
public Integer getStaffID() {
return staffID;
}
public void setStaffID(Integer staffID) {
this.staffID = staffID;
}
public Date getRtTime() {
return rtTime;
}
public void setRtTime(Date rtTime) {
this.rtTime = rtTime;
}
public Integer getRtAmount() {
return rtAmount;
}
public void setRtAmount(Integer rtAmount) {
this.rtAmount = rtAmount;
}
public String getRtRemark() {
return rtRemark;
}
public void setRtRemark(String rtRemark) {
this.rtRemark = rtRemark;
}
}
//他们依次的各个Dao
/**
*
*/
package com.yidu.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import com.yidu.model.Room;
import com.yidu.utils.JDBCTools;
/**
-
描述:房间Dao
-
@author zhouyuxian
-
@date 2019年8月28日 下午7:50:50
-
@version 1.0
*/
public class RoomDao {static Logger log = Logger.getLogger(“RoomDao.class”);
/**
- 添加房间
- @param room
- @return
*/
public int insert(Room room){
int rows = 0;
Connection con = null;
PreparedStatement pstm = null;
try {
con = JDBCTools.getCon();
String sql = “insert into room values(null,?,?,?,?)”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setString(1, room.getName());
pstm.setString(2, room.getType());
pstm.setString(3, room.getPrice());
pstm.setString(4, room.getState());
rows = pstm.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm);
}
return rows;
}
/**
- 根据ID删除房间
- @param roomID
- @return
*/
public int delete(int roomID){
int rows = 0;
Connection con = null;
PreparedStatement pstm = null;
try {
con = JDBCTools.getCon();
String sql = “delete from room where room_id=?”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setInt(1, roomID);
rows = pstm.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm);
}
return rows;
}
/**
- 修改房间信息
- @param room
- @return
*/
public int update(Room room){
int rows = 0;
Connection con = null;
PreparedStatement pstm = null;
try {
con = JDBCTools.getCon();
String sql = “update room set room_name=?,room_type=?,room_price=?,room_state=? where room_id=?”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setString(1, room.getName());
pstm.setString(2, room.getType());
pstm.setString(3, room.getPrice());
pstm.setString(4, room.getState());
pstm.setInt(5, room.getRoomID());
rows = pstm.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm);
}
return rows;
}
/**
- 查询所有房间
- @return
*/
public List selectAll(){
List list = new ArrayList();
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try {
con = JDBCTools.getCon();
String sql = “select * from room”;
log.info(sql);
pstm = con.prepareStatement(sql);
rs = pstm.executeQuery();
while(rs.next()){
Room room = new Room();
room.setRoomID(rs.getInt(“room_id”));
room.setName(rs.getString(“room_name”));
room.setType(rs.getString(“room_type”));
room.setPrice(rs.getString(“room_price”));
room.setState(rs.getString(“room_state”));
list.add(room);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm, rs);
}
return list;
}
/**
- 根据ID查询
- @param roomID
- @return
*/
public Room selectID(int roomID){
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try {
con = JDBCTools.getCon();
String sql = “select * from room where room_id=?”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setInt(1, roomID);
rs = pstm.executeQuery();
while(rs.next()){
Room room = new Room();
room.setRoomID(rs.getInt(“room_id”));
room.setName(rs.getString(“room_name”));
room.setType(rs.getString(“room_type”));
room.setPrice(rs.getString(“room_price”));
room.setState(rs.getString(“room_state”));
return room;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm, rs);
}
return null;
}
}
/**
*
*/
package com.yidu.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import com.yidu.model.Client;
import com.yidu.utils.JDBCTools;
/**
-
描述:客户Dao
-
@author zhouyuxian
-
@date 2019年8月28日 下午10:39:55
-
@version 1.0
*/
public class ClientDao {
static Logger log = Logger.getLogger(“ClientDao.class”);/**
- 添加客户
- @param client
- @return
*/
public int insert(Client client){
int rows = 0;
Connection con = null;
PreparedStatement pstm = null;
try {
con = JDBCTools.getCon();
String sql = “insert into room values(null,?,?,?,?)”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setString(1, client.getClientName());
pstm.setString(2, client.getClientSex());
pstm.setString(3, client.getClientBirth());
pstm.setString(4, client.getClientPhone());
rows = pstm.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm);
}
return rows;
}
/**
- 根据ID删除客户
- @param clientID
- @return
*/
public int delete(int clientID){
int rows = 0;
Connection con = null;
PreparedStatement pstm = null;
try {
con = JDBCTools.getCon();
String sql = “delete from client where client_id=?”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setInt(1, clientID);
rows = pstm.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm);
}
return rows;
}
/**
- 修改客户信息
- @param client
- @return
*/
public int update(Client client){
int rows = 0;
Connection con = null;
PreparedStatement pstm = null;
try {
con = JDBCTools.getCon();
String sql = “update client set client_name=?,client_sex=?,client_birthday=?,client_phone=? where client_id=?”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setString(1, client.getClientName());
pstm.setString(2, client.getClientSex());
pstm.setString(3, client.getClientBirth());
pstm.setString(4, client.getClientPhone());
pstm.setInt(5, client.getClientID());
rows = pstm.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm);
}
return rows;
}
/**
- 查询所有客户
- @return
*/
public List selectAll(){
List list = new ArrayList();
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try {
con = JDBCTools.getCon();
String sql = “select * from client”;
log.info(sql);
pstm = con.prepareStatement(sql);
rs = pstm.executeQuery();
while(rs.next()){
Client client = new Client();
client.setClientID(rs.getInt(“client_id”));
client.setClientName(rs.getString(“client_name”));
client.setClientSex(rs.getString(“client_sex”));
client.setClientBirth(rs.getString(“client_birthday”));
client.setClientPhone(rs.getString(“client_phone”));
list.add(client);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm, rs);
}
return list;
}
/**
- 根据ID查询
- @param clientID
- @return
*/
public Client selectID(int clientID){
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try {
con = JDBCTools.getCon();
String sql = “select * from client where client_id=?”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setInt(1, clientID);
rs = pstm.executeQuery();
while(rs.next()){
Client client = new Client();
client.setClientID(rs.getInt(“client_id”));
client.setClientName(rs.getString(“client_name”));
client.setClientSex(rs.getString(“client_sex”));
client.setClientBirth(rs.getString(“client_birthday”));
client.setClientPhone(rs.getString(“client_phone”));
return client;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm, rs);
}
return null;
}
}
/**
*
*/
package com.yidu.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import com.yidu.model.Department;
import com.yidu.utils.JDBCTools;
/**
-
描述:部门Dao
-
@author zhouyuxian
-
@date 2019年8月28日 下午10:56:10
-
@version 1.0
*/
public class DepartmentDao {
static Logger log = Logger.getLogger(“DepartmentDao.class”);/**
- 添加部门
- @param dt
- @return
*/
public int insert(Department dt){
int rows = 0;
Connection con = null;
PreparedStatement pstm = null;
try {
con = JDBCTools.getCon();
String sql = “insert into department values(null,?,?)”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setString(1, dt.getDtName());
pstm.setString(2, dt.getDtPhone());
rows = pstm.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm);
}
return rows;
}
/**
- 根据ID删除部门
- @param departmentID
- @return
*/
public int delete(int departmentID){
int rows = 0;
Connection con = null;
PreparedStatement pstm = null;
try {
con = JDBCTools.getCon();
String sql = “delete from client where department_id=?”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setInt(1, departmentID);
rows = pstm.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm);
}
return rows;
}
/**
- 修改部门信息
- @param dt
- @return
*/
public int update(Department dt){
int rows = 0;
Connection con = null;
PreparedStatement pstm = null;
try {
con = JDBCTools.getCon();
String sql = “update department set department_name=?,department_phone=? where department_id=?”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setString(1, dt.getDtName());
pstm.setString(2, dt.getDtPhone());
pstm.setInt(3, dt.getDtID());
rows = pstm.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm);
}
return rows;
}
/**
- 查询所有客户
- @return
*/
public List selectAll(){
List list = new ArrayList();
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try {
con = JDBCTools.getCon();
String sql = “select * from department”;
log.info(sql);
pstm = con.prepareStatement(sql);
rs = pstm.executeQuery();
while(rs.next()){
Department dt = new Department();
dt.setDtID(rs.getInt(“department_id”));
dt.setDtName(rs.getString(“department_name”));
dt.setDtPhone(rs.getString(“department_phone”));
list.add(dt);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm, rs);
}
return list;
}
/**
- 根据ID查询
- @param departmentID
- @return
*/
public Department selectID(int departmentID){
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try {
con = JDBCTools.getCon();
String sql = “select * from department where department_id=?”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setInt(1, departmentID);
rs = pstm.executeQuery();
while(rs.next()){
Department dt = new Department();
dt.setDtID(rs.getInt(“department_id”));
dt.setDtName(rs.getString(“department_name”));
dt.setDtPhone(rs.getString(“department_phone”));
return dt;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm, rs);
}
return null;
}
}
/**
*
*/
package com.yidu.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import com.yidu.model.Staff;
import com.yidu.utils.JDBCTools;
/**
-
描述:员工Dao
-
@author zhouyuxian
-
@date 2019年8月28日 下午11:09:31
-
@version 1.0
*/
public class StaffDao {
static Logger log = Logger.getLogger(“StaffDao.class”);/**
- 添加员工
- @param staff
- @return
*/
public int insert(Staff staff){
int rows = 0;
Connection con = null;
PreparedStatement pstm = null;
try {
con = JDBCTools.getCon();
String sql = “insert into staff values(null,?,?,?)”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setInt(1, staff.getDtID());
pstm.setString(2, staff.getStaffName());
pstm.setString(3, staff.getStaffSex());
rows = pstm.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm);
}
return rows;
}
/**
- 根据ID删除员工
- @param staffID
- @return
*/
public int delete(int staffID){
int rows = 0;
Connection con = null;
PreparedStatement pstm = null;
try {
con = JDBCTools.getCon();
String sql = “delete from staff where staff_id=?”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setInt(1, staffID);
rows = pstm.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm);
}
return rows;
}
/**
- 修改员工信息
- @param staff
- @return
*/
public int update(Staff staff){
int rows = 0;
Connection con = null;
PreparedStatement pstm = null;
try {
con = JDBCTools.getCon();
String sql = “update staff set department_id=?,staff_name=?,staff_sex=? where staff_id=?”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setInt(1, staff.getDtID());
pstm.setString(2, staff.getStaffName());
pstm.setString(3, staff.getStaffSex());
pstm.setInt(4, staff.getStaffID());
rows = pstm.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm);
}
return rows;
}
/**
- 查询所有员工
- @return
*/
public List selectAll(){
List list = new ArrayList();
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try {
con = JDBCTools.getCon();
String sql = “select * from staff”;
log.info(sql);
pstm = con.prepareStatement(sql);
rs = pstm.executeQuery();
while(rs.next()){
Staff staff = new Staff();
staff.setStaffID(rs.getInt(“staff_id”));
staff.setDtID(rs.getInt(“department_id”));
staff.setStaffName(rs.getString(“staff_name”));
staff.setStaffSex(rs.getString(“staff_sex”));
list.add(staff);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm, rs);
}
return list;
}
/**
- 根据ID查询
- @param staffID
- @return
*/
public Staff selectID(int staffID){
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try {
con = JDBCTools.getCon();
String sql = “select * from staff where staff_id=?”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setInt(1, staffID);
rs = pstm.executeQuery();
while(rs.next()){
Staff staff = new Staff();
staff.setStaffID(rs.getInt(“staff_id”));
staff.setDtID(rs.getInt(“department_id”));
staff.setStaffName(rs.getString(“staff_name”));
staff.setStaffSex(rs.getString(“staff_sex”));
return staff;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm, rs);
}
return null;
}
}
/**
*
*/
package com.yidu.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import com.yidu.model.Hotel;
import com.yidu.utils.JDBCTools;
/**
-
描述:酒店Dao
-
@author zhouyuxian
-
@date 2019年8月28日 下午11:33:52
-
@version 1.0
*/
public class HotelDao {
static Logger log = Logger.getLogger(“HotelDao.class”);/**
- 添加酒店信息
- @param hotel
- @return
*/
public int insert(Hotel hotel){
int rows = 0;
Connection con = null;
PreparedStatement pstm = null;
try {
con = JDBCTools.getCon();
String sql = “insert into hotel values(null,?,?,?)”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setString(1, hotel.getHotelName());
pstm.setString(2, hotel.getHotelAddress());
pstm.setString(3, hotel.getHotelType());
rows = pstm.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm);
}
return rows;
}
/**
- 根据ID删除酒店信息
- @param hotelID
- @return
*/
public int delete(int hotelID){
int rows = 0;
Connection con = null;
PreparedStatement pstm = null;
try {
con = JDBCTools.getCon();
String sql = “delete from hotel where hotel_id=?”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setInt(1, hotelID);
rows = pstm.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm);
}
return rows;
}
/**
- 修改酒店信息
- @param hotel
- @return
*/
public int update(Hotel hotel){
int rows = 0;
Connection con = null;
PreparedStatement pstm = null;
try {
con = JDBCTools.getCon();
String sql = “update hotel set hotel_name=?,hotel_address=?,hotel_type=? where hotel_id=?”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setString(1, hotel.getHotelName());
pstm.setString(2, hotel.getHotelAddress());
pstm.setString(3, hotel.getHotelType());
pstm.setInt(4, hotel.getHotelID());
rows = pstm.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm);
}
return rows;
}
/**
- 查询所有酒店信息
- @return
*/
public List selectAll(){
List list = new ArrayList();
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try {
con = JDBCTools.getCon();
String sql = “select * from hotel”;
log.info(sql);
pstm = con.prepareStatement(sql);
rs = pstm.executeQuery();
while(rs.next()){
Hotel hotel = new Hotel();
hotel.setHotelID(rs.getInt(“hotel_id”));
hotel.setHotelName(rs.getString(“hotel_name”));
hotel.setHotelAddress(rs.getString(“hotel_address”));
hotel.setHotelType(rs.getString(“hotel_type”));
list.add(hotel);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm, rs);
}
return list;
}
/**
- 根据ID查询
- @param hotelID
- @return
*/
public Hotel selectID(int hotelID){
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try {
con = JDBCTools.getCon();
String sql = “select * from hotel where hotel_id=?”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setInt(1, hotelID);
rs = pstm.executeQuery();
while(rs.next()){
Hotel hotel = new Hotel();
hotel.setHotelID(rs.getInt(“hotel_id”));
hotel.setHotelName(rs.getString(“hotel_name”));
hotel.setHotelAddress(rs.getString(“hotel_address”));
hotel.setHotelType(rs.getString(“hotel_type”));
return hotel;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm, rs);
}
return null;
}
}
/**
*
*/
package com.yidu.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import com.yidu.model.Reservation;
import com.yidu.utils.JDBCTools;
/**
-
描述:订房ID
-
@author zhouyuxian
-
@date 2019年8月28日 下午11:49:27
-
@version 1.0
*/
public class ReservationDao {
static Logger log = Logger.getLogger(“ReservationDao.class”);/**
- 添加订房信息
- @param rt
- @return
*/
public int insert(Reservation rt){
int rows = 0;
Connection con = null;
PreparedStatement pstm = null;
try {
con = JDBCTools.getCon();
String sql = “insert into reservation values(null,?,?,?,?,?,?,?)”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setInt(1, rt.getRoomID());
pstm.setInt(2, rt.getClientID());
pstm.setInt(3, rt.getStaffID());
pstm.setDate(4, rt.getRtTime());
pstm.setInt(5, rt.getRtAmount());
pstm.setString(6, rt.getRtRemark());
pstm.setInt(7, rt.getRtHotel());
rows = pstm.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm);
}
return rows;
}
/**
- 根据ID删除酒店信息
- @param hotelID
- @return
*/
public int delete(int hotelID){
int rows = 0;
Connection con = null;
PreparedStatement pstm = null;
try {
con = JDBCTools.getCon();
String sql = “delete from hotel where hotel_id=?”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setInt(1, hotelID);
rows = pstm.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm);
}
return rows;
}
/**
- 修改酒店信息
- @param rt
- @return
*/
public int update(Reservation rt){
int rows = 0;
Connection con = null;
PreparedStatement pstm = null;
try {
con = JDBCTools.getCon();
String sql = “update reservation set room_id=?,client_id=?,staff_id=?,reservation_time=?,”
+ “reservation_amount=?,reservation_remark=?,hotel_id=? where reservation_id=?”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setInt(1, rt.getRoomID());
pstm.setInt(2, rt.getClientID());
pstm.setInt(3, rt.getStaffID());
pstm.setDate(4, rt.getRtTime());
pstm.setInt(5, rt.getRtAmount());
pstm.setString(6, rt.getRtRemark());
pstm.setInt(7, rt.getRtHotel());
pstm.setInt(8, rt.getRtID());
rows = pstm.executeUpdate();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm);
}
return rows;
}
/**
- 查询所有订房信息
- @return
*/
public List selectAll(){
List list = new ArrayList();
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try {
con = JDBCTools.getCon();
String sql = “select * from reservation”;
log.info(sql);
pstm = con.prepareStatement(sql);
rs = pstm.executeQuery();
while(rs.next()){
Reservation rt = new Reservation();
rt.setRtID(rs.getInt(“reservation_id”));
rt.setRoomID(rs.getInt(“room_id”));
rt.setClientID(rs.getInt(“client_id”));
rt.setStaffID(rs.getInt(“staff_id”));
rt.setRtTime(rs.getDate(“reservation_time”));
rt.setRtAmount(rs.getInt(“reservation_amount”));
rt.setRtRemark(rs.getString(“reservation_remark”));
rt.setRtHotel(rs.getInt(“hotel_id”));
list.add(rt);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm, rs);
}
return list;
}
/**
- 根据ID查询
- @param rtID
- @return
*/
public Reservation selectID(int rtID){
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try {
con = JDBCTools.getCon();
String sql = “select * from Reservation where reservation_id=?”;
log.info(sql);
pstm = con.prepareStatement(sql);
pstm.setInt(1, rtID);
rs = pstm.executeQuery();
while(rs.next()){
Reservation rt = new Reservation();
rt.setRtID(rs.getInt(“reservation_id”));
rt.setRoomID(rs.getInt(“room_id”));
rt.setClientID(rs.getInt(“client_id”));
rt.setStaffID(rs.getInt(“staff_id”));
rt.setRtTime(rs.getDate(“reservation_time”));
rt.setRtAmount(rs.getInt(“reservation_amount”));
rt.setRtRemark(rs.getString(“reservation_remark”));
rt.setRtHotel(rs.getInt(“hotel_id”));
return rt;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCTools.close(con, pstm, rs);
}
return null;
}
}