-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDisplay.java
More file actions
executable file
·150 lines (138 loc) · 5.46 KB
/
Display.java
File metadata and controls
executable file
·150 lines (138 loc) · 5.46 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
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.Properties;
import java.sql.ResultSet;
public class Display {
public static void main(String[] args) throws SQLException {
String protocol = "jdbc:derby:";
String dbName = "iRate";
String connStr = protocol + dbName + ";create=true";
Properties props = new Properties(); // connection properties
props.put("user", "user1");
props.put("password", "user1");
try (
// connect to the database using URL
Connection conn = DriverManager.getConnection(connStr, props);
// statement is channel for sending commands thru connection
Statement stmt = conn.createStatement();
) {
try {
// query for contents of employee table
String queryInfo =
"select * "
+ "from CUSTOMER ";
ResultSet rs = stmt.executeQuery(queryInfo);
System.out.println("\nCustomer:");
System.out.printf("%-40s %-16s %-16s %-16s %-16s\n",
"CustomerID", "First Name", "Last Name", "Email", "Date Joined");
System.out.printf("%-40s %-16s %-16s %-16s %-16s\n",
"--------", "--------", "--------", "--------", "-------");
while (rs.next()) {
String customerIDString = rs.getString(1);
String firstName = rs.getString(2);
String lastName = rs.getString(3);
String email = rs.getString(4);
String time = rs.getTimestamp(5).toString();
System.out.printf("%-40s %-16s %-16s %-16s %-16s\n",
customerIDString, firstName, lastName, email, time);
}
//rs.close();
} catch (Exception e) {
System.out.println("Could not display table view.");
}
try {
// query for contents of employee table
String queryInfo =
"select * "
+ "from MOVIE ";
ResultSet rs = stmt.executeQuery(queryInfo);
System.out.println("\nMovie:");
System.out.printf("%-40s %-16s\n",
"MovieID", "Title");
System.out.printf("%-40s %-16s\n",
"--------", "--------");
while (rs.next()) {
String movieIDString = rs.getString(1);
String title = rs.getString(2);
System.out.printf("%-40s %-16s\n",
movieIDString, title);
}
//rs.close();
} catch (Exception e) {
System.out.println("Could not display table view.");
}
try {
// query for contents of employee table
String queryInfo =
"select * "
+ "from ATTENDANCE ";
ResultSet rs = stmt.executeQuery(queryInfo);
System.out.println("\nAttendance:");
System.out.printf("%-40s %-32s %-16s\n",
"MovieID", "Attendance Date", "Customer ID");
System.out.printf("%-40s %-32s %-16s\n",
"--------", "--------", "--------");
while (rs.next()) {
String movieIDString1 = rs.getString(1);
String attendanceDate = rs.getTimestamp(2).toString();
String customerIDString = rs.getString(3);
System.out.printf("%-40s %-32s %-16s\n",
movieIDString1, attendanceDate, customerIDString);
}
//rs.close();
} catch (Exception e) {
System.out.println("Could not display table view.");
}
try {
// query for contents of employee table
String queryInfo =
"select * "
+ "from REVIEW ";
ResultSet rs = stmt.executeQuery(queryInfo);
System.out.println("\nReview:");
System.out.printf("%-40s %-32s %-40s %-16s %-16s %-16s\n",
"MovieID", "Review Date", "Customer ID", "Rating", "Review", "ReviewID");
System.out.printf("%-40s %-32s %-40s %-16s %-16s %-16s\n",
"--------", "--------", "--------", "--------", "-------", "--------");
while (rs.next()) {
String movieIDString = rs.getString(1);
String reviewDate = rs.getTimestamp(2).toString();
String customerIDString = rs.getString(3);
int rating = rs.getInt(4);
String review = rs.getString(5);
String reviewIDString = rs.getString(6);
System.out.printf("%-40s %-32s %-40s %-16d %-16s %-16s\n",
movieIDString, reviewDate, customerIDString, rating, review, reviewIDString);
}
//rs.close();
} catch (Exception e) {
System.out.println("Could not display table view.");
}
try {
// query for contents of employee table
String queryInfo =
"select * "
+ "from ENDORSEMENT ";
ResultSet rs = stmt.executeQuery(queryInfo);
System.out.println("\nEndorsement:");
System.out.printf("%-40s %-40s %-16s \n",
"CustomerID", "ReviewID", "Date of Endorsement");
System.out.printf("%-40s %-40s %-16s \n",
"--------", "--------", "--------");
while (rs.next()) {
String customerIDString = rs.getString(1);
String reviewIDString = rs.getString(2);
String dateOfEndorsement = rs.getTimestamp(3).toString();
System.out.printf("%-40s %-40s %-16s \n",
customerIDString, reviewIDString, dateOfEndorsement);
}
//rs.close();
} catch (Exception e) {
System.out.println("Could not display table view.");
}
}
}
}