-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintTable.java
More file actions
executable file
·168 lines (158 loc) · 6.14 KB
/
PrintTable.java
File metadata and controls
executable file
·168 lines (158 loc) · 6.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import java.sql.*;
import java.util.*;
/*
* This class communicates between user interface and databse to complete
* user required operation. The class is responsible to prompt the user
* for the input, issue a SQL statement to the databse and finally print the
* result to the console.
*/
public class PrintTable {
private Connection conn;
private Scanner input;
public PrintTable(Connection connection, Scanner input){
this.conn = connection;
this.input = input;
}
public void printHotel(){
System.out.println();
try{
PreparedStatement ps = null;
ps = conn.prepareStatement("SELECT * FROM hotel");
ResultSet rs = ps.executeQuery();
System.out.println("id|name|address|phone");
while(rs.next()){
System.out.println("" + rs.getInt("id") + "|" + rs.getString("name") + "|" + rs.getString("address") + "|" + rs.getString("phone"));
}
} catch(SQLException e){
e.printStackTrace();
}
System.out.println();
}
public void printCustomer(){
System.out.println();
try{
PreparedStatement ps = null;
ps = conn.prepareStatement("SELECT * FROM customer");
ResultSet rs = ps.executeQuery();
System.out.println("id|name|ssn|gender|phone|email|address");
while(rs.next()){
System.out.println("" + rs.getInt("id") + "|" + rs.getString("name") + "|" + rs.getString("ssn") + "|" + rs.getString("gender") + "|" + rs.getString("phone") + "|" + rs.getString("email") + "|" + rs.getString("address"));
}
} catch(SQLException e){
e.printStackTrace();
}
System.out.println();
}
public void printStaff(){
System.out.println();
try{
PreparedStatement ps = null;
ps = conn.prepareStatement("SELECT * FROM staff");
ResultSet rs = ps.executeQuery();
System.out.println("id|ssn|name|age|gender|title|department|phone|address|hotel_id");
while(rs.next()){
System.out.println("" + rs.getInt("id") + "|" + rs.getString("ssn") + "|" + rs.getString("name") + "|" + rs.getInt("age") + "|" + rs.getString("gender") + "|" + rs.getString("title") + "|" + rs.getString("department") + "|" + rs.getString("phone") + "|" + rs.getString("address") + "|" + rs.getInt("hotel_id"));
}
} catch(SQLException e){
e.printStackTrace();
}
System.out.println();
}
public void printRoomType(){
System.out.println();
try{
PreparedStatement ps = null;
ps = conn.prepareStatement("SELECT * FROM room_type");
ResultSet rs = ps.executeQuery();
System.out.println("category|occupancy|nightly_rate");
while(rs.next()){
System.out.println("" + rs.getString("category") + "|" + rs.getInt("occupancy") + "|" + rs.getInt("nightly_rate"));
}
} catch(SQLException e){
e.printStackTrace();
}
System.out.println();
}
public void printRoom(){
System.out.println();
try{
PreparedStatement ps = null;
ps = conn.prepareStatement("SELECT * FROM room");
ResultSet rs = ps.executeQuery();
System.out.println("room_number|category|occupancy|availability|hotel_id");
while(rs.next()){
System.out.println("" + rs.getInt("room_number") + "|" + rs.getString("category") + "|" + rs.getInt("occupancy") + "|" + rs.getInt("availability") + "|" + rs.getInt("hotel_id"));
}
} catch(SQLException e){
e.printStackTrace();
}
System.out.println();
}
public void printCheckin(){
System.out.println();
try{
PreparedStatement ps = null;
ps = conn.prepareStatement("SELECT * FROM checkin");
ResultSet rs = ps.executeQuery();
System.out.println("id|current_occupancy|start_date|end_date|start_time|end_time|cstaff_id|sstaff_id|fdstaff_id|customer_id");
while(rs.next()){
System.out.print("" + rs.getInt("id") + "|" + rs.getInt("current_occupancy") + "|");
String start_date = rs.getString("start_date");
start_date = start_date.substring(0, start_date.indexOf(' '));
System.out.print(start_date + "|");
String end_date = rs.getString("end_date");
end_date = end_date.substring(0, end_date.indexOf(' '));
System.out.print(end_date + "|");
System.out.println(rs.getString("start_time") + "|" + rs.getString("end_time") + "|" + rs.getString("cstaff_id") + "|" + rs.getString("sstaff_id") + "|" + rs.getString("fdstaff_id") + "|" + rs.getInt("customer_id"));
}
} catch(SQLException e){
e.printStackTrace();
}
System.out.println();
}
public void printServiceRecord(){
System.out.println();
try{
PreparedStatement ps = null;
ps = conn.prepareStatement("SELECT * FROM service_record");
ResultSet rs = ps.executeQuery();
System.out.println("id|type|amount|checkin_id");
while(rs.next()){
System.out.println("" + rs.getInt("id") + "|" + rs.getString("type") + "|" + rs.getInt("amount") + "|" + rs.getInt("checkin_id"));
}
} catch(SQLException e){
e.printStackTrace();
}
System.out.println();
}
public void printBillingAccount(){
System.out.println();
try{
PreparedStatement ps = null;
ps = conn.prepareStatement("SELECT * FROM billing");
ResultSet rs = ps.executeQuery();
System.out.println("id|billing_addr|payment_method|card_number|customer_id|bstaff_id");
while(rs.next()){
System.out.println("" + rs.getInt("id") + "|" + rs.getString("billing_addr") + "|" + rs.getString("payment_method") + "|" + rs.getString("card_number") + "|" + rs.getInt("customer_id") + "|" + rs.getInt("bstaff_id"));
}
} catch(SQLException e){
e.printStackTrace();
}
System.out.println();
}
public void printReserveFor(){
System.out.println();
try{
PreparedStatement ps = null;
ps = conn.prepareStatement("SELECT * FROM reserve_for");
ResultSet rs = ps.executeQuery();
System.out.println("hotel_id|room_number|checkin_id");
while(rs.next()){
System.out.println("" + rs.getInt("hotel_id") + "|" + rs.getInt("room_number") + "|" + rs.getInt("checkin_id"));
}
} catch(SQLException e){
e.printStackTrace();
}
System.out.println();
}
}