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

📄 brbookcontroller.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;
import library.admin;


public class brBookController extends Controller {
	 public void doPost (HttpServletRequest req,
				HttpServletResponse res) throws ServletException, IOException {
		
		String bookid=null, readerid=null,isbn=null;

		HttpSession session = req.getSession();
		
		bookid = req.getParameter("bookid");
		readerid = req.getParameter("readerid");
		isbn = req.getParameter("isbn");
		session = req.getSession();
	
		boolean br =true;
		boolean br1 = true;
	
		try{
			DBConnection connection = DBConnection.Instance();
			String sql = "select * from fakuan where readerid ='"+readerid+"'";
			ResultSet w = null;
			w = connection.runQuery(sql);
			if(w.next()){
				br =false;
			}
			sql = "select * from bookhavebr where findid ='"+bookid+"'";
			w = connection.runQuery(sql);
			if(w.next()){
				br1 =false;
			}
		}catch(Exception e){
			sendErrorRedirect(req, res, e);
		}
		try {
		    if(br == false){	
			    res.sendRedirect("../searchbookresult.jsp?jieguo=failed1");
		    }else if(br1==false){
		    	 res.sendRedirect("../searchbookresult.jsp?jieguo=failed2");
		    }else{
			    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 = "insert into bookhavebr (findid,readerid,brdata,redata,xujie) " +
			    		" values ('"+bookid+"','"+readerid+"',CURDATE(),DATE_ADD(CURDATE(), Interval 1 month),3"+")";
			    boolean rs=stmt.execute(sql);
			    sql = "update booktitle set isin = 'no' 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("../searchbookresult.jsp?jieguo=success");		
		    }
		} catch (Exception e2) {
			sendErrorRedirect(req, res, e2);
		}
		
	    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -