-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaderboard.jsp
110 lines (96 loc) · 2.92 KB
/
leaderboard.jsp
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
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!--Import some libraries that have classes that we need -->
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Ride Share - Leaderboard</title>
</head>
<body>
<%
try {
//Create a connection string
String url = "jdbc:mysql://cs336finalproject.cl75kudzatsx.us-east-1.rds.amazonaws.com:3306/users";
//Load JDBC driver - the interface standardizing the connection procedure. Look at WEB-INF\lib for a mysql connector jar file, otherwise it fails.
Class.forName("com.mysql.jdbc.Driver");
//Create a connection to your DB
Connection con = DriverManager.getConnection(url, "cs336project", "csteam14");
Statement stmt = con.createStatement();
String currentun = (String)session.getAttribute("currentuser");
//Make a SELECT query from the users table with the username and password matches with the input
String str = "SELECT RidesGiven, RidesTaken, Rating FROM userlist WHERE AccountType = 'User' AND Username = \"" + currentun + "\"";
//Run the query against the database.
ResultSet result = stmt.executeQuery(str);
%>
<div align="center">
<b>My statistics:</b>
<br>
<table border="1">
<tr>
<td>Rides Given</td>
<td>Rides Taken</td>
<td>Rating</td>
</tr>
<%
while(result.next())
{
%>
<tr>
<td align="center"><%=result.getString("RidesGiven") %></td>
<td align="center"><%=result.getInt("RidesTaken") %></td>
<td><%=result.getDouble("Rating") %></td>
</tr>
<%
}
%>
</table>
</div>
<% //Make a SELECT query from the users table with the username and password matches with the input
str = "SELECT Username, RidesGiven, Rating FROM userlist WHERE AccountType = 'User' ORDER BY RidesGiven DESC";
//Run the query against the database.
result = stmt.executeQuery(str);
%>
<div align="center">
<br>
<b>LEADERBOARD (TOP 10)</b>
<table border="1">
<tr>
<td>Username</td>
<td>Rides Given</td>
<td>Rating</td>
</tr>
<%
int shown = 0;
while(result.next())
{
if(shown > 9){
break;
}
%>
<tr>
<td><%=result.getString("Username") %></td>
<td align="center"><%=result.getInt("RidesGiven") %></td>
<td><%=result.getDouble("Rating") %></td>
</tr>
<%
shown++;
}
%>
</table>
</div>
<%
result.close();
stmt.close();
con.close();
} catch (Exception ex) {
out.print("System failure");
}
%>
<br>
<br>
[<a href="homepage.jsp">Main page</a>] [<a href="https://github.com/NitantP/Ride-Share/blob/master/leaderboard.jsp">GitHub Page</a>] [<a href="index.jsp">Logout</a>]
</body>
</html>