⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 returnbookcontroller.java

📁 学习jsp时做的一个书馆
💻 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 + -