Repository navigation
Expand file tree
/
Copy pathgamebd.jsp
More file actions
159 lines (151 loc) · 4.9 KB
/
Copy pathgamebd.jsp
File metadata and controls
159 lines (151 loc) · 4.9 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
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.*" %>
<% request.setCharacterEncoding("utf-8"); %>
<%
boolean isSearch = false;
//String id = (String)session.getAttribute("id");
//int score = Integer.parseInt((String)request.getParameter("score"));
//String username = (String)session.getAttribute("username");
String userId = "dong22";
String username = "dongdong2";
int score = 90;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
String jdbcurl = "jdbc:mysql://localhost:3306/rism?serverTimezone=UTC";
conn = DriverManager.getConnection(jdbcurl, "root", "0000");
stmt = conn.createStatement();
String sql = "select * from game";
rs = stmt.executeQuery(sql);
//여기서 전부 탐색
while(rs.next()){
//찾으면 갱신
if(rs.getString("userId").equals(userId)){
// update game set score = 123132 where name = 'dong2';
//전에 했던 점수가 더 높으면 갱신 안 함
if(rs.getInt("score") < score){
String temp = String.format("update game set score = %d where userId = '%s';", score, userId);
stmt.executeUpdate(temp);
}
isSearch = true;
break;
}
}
//찾지 못 하면 추가
if(isSearch == false){
String temp = String.format("insert into game (userId, username, score) values ('%s', '%s', %d);", userId, username, score);
stmt.executeUpdate(temp);
}
rs = stmt.executeQuery("SELECT * FROM game ORDER BY score DESC");
}
catch(Exception e) {
out.println("DB 연동 오류입니다. : " + e.getMessage());
}
//response.sendRedirect("main.html");
%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="images/mark.png">
<title>Shooting</title>
<style>
@font-face{
font-family: "CookieRunFont_OTF/CookieRun Bold.otf";
src:url("CookieRunFont_OTF/CookieRun Bold.otf")format("truetype");
}
body{
font-family: "CookieRunFont_OTF/CookieRun Bold.otf";
}
a { color: black; }
.ranking{
display: flex;
flex-direction: column;
align-items: center;
}
table.type10 {
border-collapse: collapse;
text-align: left;
line-height: 1.5;
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
margin: 20px 10px;
}
table.type10 thead th {
width: 150px;
padding: 10px;
font-weight: bold;
vertical-align: top;
color: #fff;
background: #e7708d;
margin: 20px 10px;
}
table.type10 tbody th {
width: 150px;
padding: 10px;
}
table.type10 td {
width: 350px;
padding: 10px;
vertical-align: top;
}
table.type10 .even {
background: #fdf3f5;
}
</style>
</head>
<body>
<div class="ranking">
<h1>RANK</h1>
<table class="type10">
<thead>
<tr>
<th scope="cols">RANK</th>
<th scope="cols">ID</th>
<th scope="cols">USER NMAE</th>
<th scope="cols">SCORE</th>
</tr>
</thead>
<tbody>
<%
boolean isPrink = false;
int iCount = 1;
while(rs.next()){
if(isPrink == false){
%>
<tr>
<td scope="row" ><%= iCount %></td>
<td ><%= rs.getString("userID") %></td>
<td ><%= rs.getString("username") %></td>
<td ><%= rs.getInt("score") %></td>
</tr>
<%
}
else{
%>
<tr>
<td scope="row" class="even"><%= iCount %></td>
<td class="even"><%= rs.getString("userID") %></td>
<td class="even"><%= rs.getString("username") %></td>
<td class="even"><%= rs.getInt("score") %></td>
</tr>
<%
}
iCount++;
isPrink = !isPrink;
}
rs.close();
stmt.close();
conn.close();
%>
</tbody>
</table>
<a href="index.html">홈페이지로 돌아가기</a>
</div>
</body>
</html>