📄 admindao.java
字号:
/*
* 创建日期 2005-10-17
*
* TODO 要更改此生成的文件的模板,请转至
* 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
package net.husthotel.datebase;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import net.husthotel.beans.Room;
/**
* @author 付俊杰
*
* TODO 要更改此生成的类型注释的模板,请转至 窗口 - 首选项 - Java - 代码样式 - 代码模板
*/
public class AdminDAO extends DataBase {
private ResultSet rst = null;
public AdminDAO() {
}
/**
* add room .
*
* @param aRoom.
* @return true/false.
* @throws SQLException.
* @throws NoRoomAvailableException.
*/
public boolean addRoom(Room aRoom) throws SQLException,
NoRoomAvailableException {
boolean boaddRoom = false;
String sql1 = "select * from room where roomNum='" + aRoom.getRoomNum()
+ "'";
String sql2 = "insert into room(roomNum,roomType,roomState,price,checkinDate,checkoutDate) values('"
+ aRoom.getRoomNum()
+ "','"
+ aRoom.getRoomStyle()
+ "','"
+ aRoom.getRoomState()
+ "','"
+ aRoom.getRoomPrice()
+ "','"
+ new Date(aRoom.getCheckinDate().getTime())
+ "','"
+ new Date(aRoom.getCheckoutDate().getTime())
+ "')";
rst = executeQuery(sql1);
if (rst.next()) {
boaddRoom = false;
throw new NoRoomAvailableException("no room available");
} else {
if (executeUpdate(sql2))
boaddRoom = true;
}
rst.close();
return boaddRoom;
}
/**
* login by name, and password.
*
* @param name.
* @param password.
* @return true/false.
* @throws SQLException.
*/
public boolean login(String name, String password)
throws SQLException {
boolean bologin = false;
String sql = "select * from admin where name='" + name
+ "'and password='" + password + "'";
rst=executeQuery(sql);
if (rst.next()) {
bologin = true;
} else {
bologin = false;
}
rst.close();
return bologin;
}
/**
* log out.
*
*/
public void logout() {
}
/**
* delete room.
*
* @param RoomNum.
* @return true/false.
* @throws SQLException.
* @throws NoRoomAvailableException.
*/
public boolean deleteRoom(String roomNum) throws SQLException,
NoRoomAvailableException {
boolean bodelete = false;
String sql = "delete from room where roomNum='" + roomNum + "'";
System.out.println("delete sql:" + sql);
if (executeUpdate(sql)) {
bodelete = true;
}
else {
bodelete = false;
throw new NoRoomAvailableException("no room availabe");
}
return bodelete;
}
/**
* modify room by roomnum.
*
* @param MRoom.
* @return true/false.
* @throws SQLException.
*/
public boolean modifyRoomInfo(Room room) throws SQLException {
boolean boModify = false;
String sql = "update room set roomType='" + room.getRoomStyle()
+ "',roomState='" + room.getRoomState() + "',price='"
+ room.getRoomPrice() + "',checkinDate='"
+ new java.sql.Date(room.getCheckinDate().getTime()) + "',checkoutDate='"
+ new java.sql.Date(room.getCheckoutDate().getTime()) + "' where roomNum='"
+ room.getRoomNum() + "'";
//----------------------------
if (executeUpdate(sql)) {
System.out.println("AdminDAO: modify room info() \n" + sql);
boModify = true;
}
else
boModify = false;
return boModify;
}
public ArrayList<Room> queryRoomInfo() throws SQLException {
ArrayList<Room> querylist;
querylist = new ArrayList<Room>();
//Room quroom = new Room(); ////新建的Order应该在 rst.next 循环中 要不然引用是指向一个对象的
String sql = "select * from room";
rst = executeQuery(sql);
while (rst.next()) {
System.out.println("rst is not null" + rst.getDate("checkinDate"));//----------------
Room quroom = new Room();
quroom.setRoomPrice(rst.getString("price"));
quroom.setCheckinDate(new java.util.Date(rst.getDate("checkinDate").getTime()));
quroom.setCheckoutDate(new java.util.Date(rst.getDate("checkoutDate").getTime()));
quroom.setRoomNum(rst.getString("roomNum"));
quroom.setRoomState(rst.getString("roomState"));
quroom.setRoomStyle(rst.getString("roomType"));
querylist.add(quroom);
}
rst.close();
return querylist;
}
public ArrayList<Room> queryRoomInfoByCondition(String querySql) throws SQLException {
ArrayList<Room> queryList = new ArrayList<Room> ();
String sql = "select * from room " + querySql;
rst = executeQuery(sql);
while(rst.next()) {
Room room = new Room();
room.setRoomPrice(rst.getString("price"));
room.setCheckinDate(new java.util.Date(rst.getDate("checkinDate").getTime()));
room.setCheckoutDate(new java.util.Date(rst.getDate("checkoutDate").getTime()));
room.setRoomNum(rst.getString("RoomNum"));
room.setRoomState(rst.getString("RoomState"));
room.setRoomStyle(rst.getString("RoomType"));
queryList.add(room);
}
rst.close();
return queryList;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -