-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete.jsp
More file actions
69 lines (61 loc) · 2.2 KB
/
delete.jsp
File metadata and controls
69 lines (61 loc) · 2.2 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
<%@ page import="java.sql.*" %>
<html>
<head>
<title>Student Management System</title>
<link rel="stylesheet" href="mystyle.css"/>
<script>
function confirmDelete() {
return confirm("Are you sure you want to delete?");
}
</script>
</head>
<body>
<center>
<h1>Delete student record </h1>
<br><br>
<%
String un = (String) session.getAttribute("un");
if (un == null) {
response.sendRedirect("index.jsp");
}
%>
<form method="POST">
<input type="number" name="rno" placeholder="Enter your rno" required min="1">
<br><br>
<button class="login-button" type="submit" name="btn">Delete</button>
<br><br>
</form>
<form method="POST">
<button class="login-button" type="submit" name="back">Back</button>
<br><br>
</form>
<%
if (request.getParameter("btn") != null) {
String rnoStr = request.getParameter("rno");
try {
int rno = Integer.parseInt(rnoStr); // Convert the String to an integer
DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
String url = "jdbc:mysql://localhost:3306/sms_19july23";
Connection con = DriverManager.getConnection(url, "root", "amishaka");
String sql = "DELETE FROM sms WHERE rno=?";
PreparedStatement pst = con.prepareStatement(sql);
pst.setInt(1, rno);
int r = pst.executeUpdate();
out.println(r + " record deleted");
con.close();
} catch (SQLException e) {
out.println("SQL issue: " + e);
} catch (NumberFormatException e) {
out.println("Invalid input for rno. Please enter a valid number.");
}
}
%>
<%
if (request.getParameter("back") != null) {
response.sendRedirect("sms.jsp");
return;
}
%>
</center>
</body>
</html>