这是一个图书馆系统
源代码在线查看: booksearch.jsp~73~
"http://www.w3.org/TR/html4/loose.dtd">
booksearch
.style1 {font-family: "黑体"}
-->
title
//java.util.Locale locale = request.getLocale();
//java.text.DateFormat dateFormat = java.text.DateFormat.getDateInstance(java.text.DateFormat.LONG,locale);
try{
int flag=0,flag1=0;String studentnumber="";
String id=Library.getid();
// String title=request.getParameter("title");
Connection conn=Library.getConn();
Statement stmt,stmt1;
stmt = conn.createStatement();
stmt1 = conn.createStatement();
ResultSet rs2 = stmt.executeQuery("select * from borrowbook where id ='" + id + "'");
//ResultSet rs6 = pstmt1.executeQuery();
while(rs2.next()){
if(rs2.getString("returnmoney").equals("no")){
flag=1;
}
}
//out.println("" + request.getParameter("title") + "");
ResultSet rs3 = stmt.executeQuery("select * from user where id ='" + id + "'");
if(rs3.next()){
studentnumber = rs3.getString("studentnumber");
}
if(request.getParameter("enter")!=null){
ResultSet rs = stmt.executeQuery("select * from book where title ='" + request.getParameter("title") + "'");
while (rs.next()){
out.println("serialnumber = " + rs.getString("serialnumber") + " ");
out.println("sortnumber = " + rs.getString("sortnumber") + " ");
out.println("title = " + rs.getString("title") + " ");
out.println("author1 = " + rs.getString("author1") + " ");
out.println("author2 = " + rs.getString("author2") + " ");
out.println("author3 = " + rs.getString("author3") + " ");
out.println("cover = " + rs.getString("cover") + " ");
out.println("bookconcern = " + rs.getString("bookconcern") + " ");
out.println("publicday = " + rs.getString("publicday") + " ");
out.println("isbn = " + rs.getString("isbn") + " ");
out.println("times = " + rs.getString("times") + " ");
out.println("prize = " + rs.getString("prize") + " ");
out.println("innumber = " + rs.getString("innumber") + " ");
out.println("outnumber = " + rs.getString("outnumber") + " ");
}
}
else if(request.getParameter("borrow")!=null && request.getParameter("title")!=null && flag==0){
// stmt = conn.createStatement();
ResultSet rs5 = stmt.executeQuery("select * from book where title ='" + request.getParameter("title") + "'");
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 ='" + request.getParameter("title") + "'";
// stmt =conn .createStatement();
stmt1.executeUpdate(newinbook);
String newoutbook = "update book set outnumber ='" + (oldoutbook+1) +"' where title ='" + request.getParameter("title") + "'";
// stmt=conn.createStatement();
stmt1.executeUpdate(newoutbook);
out.println("You succeed in borrowing this book.");}else{response.sendRedirect("fail.jsp");
}
//out.println("" + request.getParameter("title") + "");
//Statement stmt = conn.createStatement();
//ResultSet rs1 = stmt.executeQuery("select * from book where title ='" + request.getParameter("title") + "'");
//stmt = conn.createStatement();
ResultSet rs7 = stmt.executeQuery("select * from administrator");
int nowtrailnumber=0;
while(rs7.next()){
nowtrailnumber=Integer.getInteger(rs7.getString("nowtrailnumber"));}
String insertborrowbook = "insert into borrowbook(trailnumber,serialnumber,sortnumber,title,id,studentnumber,borrowdata,shouldreturndata,returndata,overdata,fee,returnmoney) values('" + nowtrailnumber + "','" + serialnumber + "','" + sortnumber +
"','" + request.getParameter("title") + "','" + 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)+"'");
//stmt=conn.createStatement();
stmt1.execute(insertborrowbook);
}
}else if(request.getParameter("return")!=null){
//stmt = conn.createStatement();
ResultSet rs4 = stmt.executeQuery("select * from borrowbook where id ='" + id + "' and title ='" + request.getParameter("title") + "' and returndata = '0'");
if(rs4.next()){
// int returndata=Integer.parseInt(rs4.getString("returndata"));
/* rs4.getString("title").equals(request.getParameter("title"));
flag1=1;
}
if(flag1==1 && request.getParameter("title")!=null){*/
// if(returndata==)
//stmt=conn.createStatement();
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 ='" + request.getParameter("title") + "'and id ='" + id + "'");
//stmt = conn.createStatement();
ResultSet rs6 = stmt.executeQuery("select * from book where title ='" + request.getParameter("title") + "'");
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 ='" + request.getParameter("title") + "'";
stmt1.executeUpdate(newinbook);
String newoutbook = "update book set outnumber ='" + (oldoutbook-1) +"' where title ='" + request.getParameter("title") + "'";
stmt1.executeUpdate(newoutbook);
out.println("You succeed in returning this book.");
}
}
}
}catch (Exception ex) {
response.sendRedirect("fail.jsp");
ex.printStackTrace();}
%>