这是一个图书馆管理系统的jsp代码
源代码在线查看: booksearchresults.jsp~5~
Search Book results
.style3 {font-size: 24px}
.style4 {font-size: 18px}
-->
try{
Connection conn=Library.getConn();
Statement stmt;
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from book where title ='" + Library.getbookstitle() + "'");
while (rs.next()){
Library.setbserialnumber(rs.getString("serialnumber"));
Library.setbsortnumber(rs.getString("sortnumber"));
Library.setbtitle(rs.getString("title"));
Library.setbauthor1(rs.getString("author1"));
Library.setbauthor2(rs.getString("author2"));
Library.setbauthor3(rs.getString("author3"));
Library.setbcover(rs.getString("cover"));
Library.setbbookconcern(rs.getString("bookconcern"));
Library.setbpublicday(rs.getString("publicday"));
Library.setbisbn(rs.getString("isbn"));
Library.setbtimes(rs.getString("times"));
Library.setbprize(rs.getString("prize"));
Library.setbinnumber(rs.getString("innumber"));}
}catch (Exception ex) {
response.sendRedirect("fail.jsp");
ex.printStackTrace();}
%>
UserRights
ModifyMessage
BookSearch
BookReturn
HaveBorrow
Search Book Results
Serial NO.:
Sort NO.:
Title:
Author1:
Author2:
Author3:
Cover:
Book Conern:
Public Day:
ISBN:
Times:
Prize:
In NO.:
try{
int flag=0,flag1=0;String studentnumber="";
String id=Library.getid();
Connection conn=Library.getConn();
Statement stmt,stmt1;
stmt = conn.createStatement();
stmt1 = conn.createStatement();
ResultSet rs2 = stmt.executeQuery("select * from borrowbook where id ='" + id + "'");
while(rs2.next()){//判断当前用户是否已经还清欠款,在borrowbook表中,flag=1代表为还清,flag=0代表还清
if(rs2.getString("returnmoney").equals("no")){
flag=1;
}
}
ResultSet rs3 = stmt.executeQuery("select * from user where id ='" + id + "'");
if(rs3.next()){
studentnumber = rs3.getString("studentnumber");
}
if(request.getParameter("borrow")!=null && Library.getbookstitle()!=null && flag==0){
ResultSet rs5 = stmt.executeQuery("select * from book where title ='" + Library.getbookstitle() + "'");
if(rs5.next()){
int oldinbook = Integer.parseInt(rs5.getString("innumber"));
int oldoutbook = Integer.parseInt(rs5.getString("outnumber"));
String serialnumber=rs5.getString("serialnumber");
String sortnumber=rs5.getString("sortnumber");
if(oldinbook>0){//判断该书有没有库存
String newinbook = "update book set innumber ='" + (oldinbook-1) +"' where title ='" + Library.getbookstitle() + "'";
stmt1.executeUpdate(newinbook);
String newoutbook = "update book set outnumber ='" + (oldoutbook+1) +"' where title ='" + Library.getbookstitle() + "'";
stmt1.executeUpdate(newoutbook);
//out.println("You succeed in borrowing this book.");
}else{response.sendRedirect("fail.jsp");
}
ResultSet rs7 = stmt.executeQuery("select * from administrator");
int nowtrailnumber=0;
while(rs7.next()){//从administrator表中获得borrowbook中的关键字trailnumber,他不因为程序结束而重新复值;
nowtrailnumber=Integer.parseInt(rs7.getString("nowtrailnumber"));}
String insertborrowbook = "insert into borrowbook(trailnumber,serialnumber,sortnumber,title,id,studentnumber,borrowdata,shouldreturndata,returndata,overdata,fee,returnmoney) values('" + nowtrailnumber + "','" + serialnumber + "','" + sortnumber +
"','" + Library.getbookstitle() + "','" + id + "','" + studentnumber + "','" + (new java.util.Date().getYear()*365 + new java.util.Date().getMonth()*31 + new java.util.Date().getDay()) + "','" + (new java.util.Date().getYear()*365 + new java.util.Date().getMonth()*31 + new java.util.Date().getDay() + 6) + "','0','0','0.00','yes')";
stmt1.execute("update administrator set nowtrailnumber ='"+(nowtrailnumber+1)+"'");//修改nowtrailnumber在administrator表中的值
stmt1.execute(insertborrowbook);
}
}else if(request.getParameter("return")!=null){
ResultSet rs4 = stmt.executeQuery("select * from borrowbook where id ='" + id + "' and title ='" + Library.getbookstitle() + "' and returndata = '0'");
if(rs4.next()){//判断在borrowbook表中是否有当前用户指定书名的书的未还记录,即returndata="0"
stmt1.executeUpdate("update borrowbook set returndata = '" + (new java.util.Date().getYear()*365 + new java.util.Date().getMonth()*31 + new java.util.Date().getDay()) + "' where title ='" + Library.getbookstitle() + "'and id ='" + id + "' and returndata = '0'");
//一个用户不会有病到在一本书还没还的情况下,再借一本相同的书吧
ResultSet rs6 = stmt.executeQuery("select * from book where title ='" + Library.getbookstitle() + "'");
while(rs6.next()){
int oldinbook = Integer.parseInt(rs6.getString("innumber"));
int oldoutbook = Integer.parseInt(rs6.getString("outnumber"));
String newinbook = "update book set innumber ='" + (oldinbook+1) +"' where title ='" + Library.getbookstitle() + "'";
stmt1.executeUpdate(newinbook);
String newoutbook = "update book set outnumber ='" + (oldoutbook-1) +"' where title ='" + Library.getbookstitle() + "'";
stmt1.executeUpdate(newoutbook);
// out.println("You succeed in returning this book.");
}
}
}
}catch (Exception ex) {
response.sendRedirect("fail.jsp");
ex.printStackTrace();}
%>