📄 delbookcontroller.java
字号:
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import library.DBConnection;
public class delBookController extends Controller {
public void doPost (HttpServletRequest req,
HttpServletResponse res) throws ServletException, IOException {
String id="";
boolean del = true;
boolean del2 = true;
HttpSession session = req.getSession();
id = req.getParameter("id");
String isbn ="";
try{
DBConnection connection = DBConnection.Instance();
String sql = "select * from fakuan where findid ='"+id+"'";
ResultSet w = null;
w = connection.runQuery(sql);
if(w.next()){
del =false;
}
sql = "select * from bookhavebr where findid ='"+id+"'";
w = connection.runQuery(sql);
if(w.next()){
del2 =false;
}
sql = "select * from booktitle where findid ='"+id+"'";
w = connection.runQuery(sql);
while(w.next()){
isbn = w.getString("isbn");
}
}catch(Exception e){
sendErrorRedirect(req, res, e);
}
try{
if(del2==false){
res.sendRedirect("../admin/searchbookresult.jsp?jieguo3=failed1&id1="+id);
}else{
DBConnection connection = DBConnection.Instance();
boolean w = false;
String sql1 = "delete from booktitle where findid ='"+id+"'";
w = connection.runUpdate(sql1);
String url ="jdbc:mysql://localhost/library?user=root&password=linux&useUnicode=true&characterEncoding=GB2312" ;
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement();
sql1 = "update books set isinno = isinno-1 where isbn = '"+isbn+"'";
boolean rs=stmt.execute(sql1);
res.sendRedirect("../admin/searchBook.jsp?jieguo2=success&id="+id);
}
}catch(Exception e){
sendErrorRedirect(req, res, e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -