-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathRemoveBookServlet.java
More file actions
38 lines (32 loc) · 1.27 KB
/
RemoveBookServlet.java
File metadata and controls
38 lines (32 loc) · 1.27 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
package servlets;
import java.sql.*;
import javax.servlet.*;
import sql.IBookConstants;
import java.io.*;
public class RemoveBookServlet extends GenericServlet {
public void service(ServletRequest req, ServletResponse res) throws IOException, ServletException {
PrintWriter pw = res.getWriter();
res.setContentType("text/html");
String bkid = req.getParameter("barcode");
try {
Connection con = DBConnection.getCon();
PreparedStatement ps = con.prepareStatement(
"delete from " + IBookConstants.TABLE_BOOK + " where " + IBookConstants.COLUMN_BARCODE + "=?");
ps.setString(1, bkid);
int k = ps.executeUpdate();
if (k == 1) {
RequestDispatcher rd = req.getRequestDispatcher("Sample.html");
rd.include(req, res);
pw.println("<div class=\"tab\">Book Removed Successfully</div>");
pw.println("<div class=\"tab\"><a href=\"RemoveBooks.html\">Remove more Books</a></div>");
} else {
RequestDispatcher rd = req.getRequestDispatcher("Sample.html");
rd.include(req, res);
pw.println("<div class=\"tab\">Book Not Available In The Store</div>");
pw.println("<div class=\"tab\"><a href=\"RemoveBooks.html\">Remove more Books</a></div>");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}