?? returnbookcontroller.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 returnBookController extends Controller {
public void doPost (HttpServletRequest req,
HttpServletResponse res) throws ServletException, IOException {
String bookid=null;
HttpSession session = req.getSession();
boolean returnbook =true;
boolean returnbook1 =true;
String isbn = "";
bookid = req.getParameter("bookid");
if(bookid.equals("")){
returnbook = false;
}
int day = 0;
String readerid="";
session = req.getSession();
try{
String url ="jdbc:mysql://localhost/library?user=root&password=linux&useUnicode=true&characterEncoding=GB2312" ;
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement();
String sql = "select TO_DAYS(NOW())-TO_DAYS(redata) as sum from bookhavebr where findid = '"+bookid+"'";
ResultSet w=stmt.executeQuery(sql);
while(w.next()){
day = Integer.parseInt(w.getString("sum"));
}
sql = "select * from bookhavebr where findid = '"+bookid+"'";
w=stmt.executeQuery(sql);
while(w.next()){
readerid = w.getString("readerid");
}
sql = "select * from bookhavebr where findid = '"+bookid+"'";
w=stmt.executeQuery(sql);
if(!w.next()){
returnbook1 = false;
}
sql = "select * from booktitle where findid = '"+bookid+"'";
w=stmt.executeQuery(sql);
if(w.next()){
isbn = w.getString("isbn");
}
}catch(Exception e){
sendErrorRedirect(req, res, e);
}
try {
if(returnbook==false){
res.sendRedirect("../returnbook.jsp?jieguo=failed");
}
if(returnbook1==false){
res.sendRedirect("../returnbook.jsp?jieguo=failed1");
}
String url ="jdbc:mysql://localhost/library?user=root&password=linux&useUnicode=true&characterEncoding=GB2312" ;
Connection conn= DriverManager.getConnection(url);
Statement stmt=conn.createStatement();
String sql = "delete from bookhavebr where findid = '"+bookid+"'";
// res.sendRedirect("../test.jsp?jieguo="+sql);
boolean rs=stmt.execute(sql);
sql = "update booktitle set isin = 'yes' where findid = '"+bookid+"'";
rs=stmt.execute(sql);
sql = "update reader set yijieshu = yijieshu-1 where readerid = '"+readerid+"'";
rs=stmt.execute(sql);
sql = "update books set isinno=isinno+1 where isbn = '"+isbn+"'";
rs=stmt.execute(sql);
res.sendRedirect("../returnbook.jsp?jieguo=success&day="+day);
} catch (Exception e2) {
sendErrorRedirect(req, res, e2);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -