代码.docx
- 文档编号:27841688
- 上传时间:2023-07-05
- 格式:DOCX
- 页数:12
- 大小:72.18KB
代码.docx
《代码.docx》由会员分享,可在线阅读,更多相关《代码.docx(12页珍藏版)》请在冰豆网上搜索。
代码
一、对数据库的操作:
1.删除记录:
<%request.setCharacterEncoding("gb2312");%>//设置编码方式
<%@includefile="conn.jsp"%>//连接数据库
<%Stringaction=request.getParameter("action");%>//获取ACTION
<%
if(action.equals("del")){//如果action等于del
Stringid=request.getParameter("id");
Statementstmt=conn.createStatement();
intrtn=stmt.executeUpdate("deletetb_bookwherebook_ID='"+id+"'");
conn.close();//关闭数据库
stmt.close();//关闭驱动
response.sendRedirect("book.jsp");//同时跳转的页面
}
%>
<%
Statementstmt=conn.createStatement();
ResultSetrs=stmt.executeQuery("select*fromLH_book");
while(rs.next()){
%>
action=ck&id=<%=rs.getString("book_ID")%>"> <%=rs.getString("book_ID")%> action=del&id=<%=rs.getString("book_ID")%>">删除 2.修改记录: <%@includefile="conn.jsp"%>//连接数据库 <% Stringid=request.getParameter("id"); Statementstmt=conn.createStatement(); ResultSetrs=stmt.executeQuery("select*fromtb_bookwherebook_ID='"+id+"'"); while(rs.next()){ %> 图书编号: ...................................... <%} conn.close(); rs.close();%> ***** 修改时,验证用户输入的新信息是否符合规范。 修改验证通过后跳入下面: <%@includefile="conn.jsp"%> <% Stringbook_id=request.getParameter("barcode"); Statementstmt=conn.createStatement(); intrtn=stmt.executeUpdate("updatetb_booksetbook_name='"+book_name+"',book_leibie='"+book_leibie+"',book_aontor='"+book_author+"',book_real='"+book_real+"',book_ceshu='"+book_ceshu+"',book_cbs='"+book_cbs+"'wherebook_ID='"+book_id+"'");//修改的记录 conn.close(); stmt.close(); %> 用javascript代码提示修改成功: alert("图书基本信息修改成功! "); window.location.href="book.jsp"; 3.添加记录: 连接数据库后,用javascript进行验证。 然后将记录插入数据库。 验证代码: functioncheck(form){ if(form.barcode.value==""){ alert("请输入条形码! ");form.barcode.focus();returnfalse; } if(form.bookName.value==""){ alert("请输入图书名称! ");form.bookName.focus();returnfalse; } if(form.price.value==""){ alert("请输入图书定价! ");form.price.focus();returnfalse; } } onClick="returncheck(form)"> 添加成功: <%@includefile="conn.jsp"%> <% Stringbook_id=request.getParameter("barcode"); Stringbook_name=request.getParameter("bookname"); Statementstmt=conn.createStatement(); intrtn=stmt.executeUpdate("insertintotb_book(book_ID,book_name) values('"+book_id+"','"+book_name+"')"); conn.close(); stmt.close(); %> alert("图书信息添加成功! "); window.location.href="book.jsp"; 二、图书信息管理: <% Stringid=request.getParameter("id"); Statementstmt=conn.createStatement(); ResultSetrs=stmt.executeQuery("select*fromLH_book_xinxiwhereBook_id='"+id+"'"); while(rs.next()){ %> 图书编号: <%=rs.getString("Book_id")%> 1.查询数据: 请选择查询依据: <%@includefile="conn.jsp"%> <% Stringcx=request.getParameter("key"); Statementstmt=conn.createStatement(); ResultSetrs=stmt.executeQuery("select*fromLH_jiewherebook_ID='"+cx+"'"); while(rs.next()){ %> 图书编码: <%=rs.getString("book_ID")%>....... <% } %> 查询成功: 请选择查询依据: <% Stringkey=request.getParameter("key"); Statementstmt=conn.createStatement(); ResultSetrs=stmt.executeQuery("select*from tb_bookwherebook_ID='"+key+"'"); while(rs.next()){ %> 图书编码: <%=rs.getString("book_name")%> <% } %> 三、还书管理: <% Stringid=request.getParameter("barcode"); Statementstmt=conn.createStatement(); ResultSetrs=stmt.executeQuery("select*from tb_jiewhereuser_I='"+id+"'andjh_h_timeisnull"); while(rs.next()){ %> ------------ 姓名: 应还时间: 5px;"><%=rs.getString("jh_j_time")%> action=gh&id=<%=rs.getString("book_ID")%>&user_id=<%=rs.getString("user_I")%>">归 还 <% } conn.close(); stmt.close(); rs.close(); %> 还书成功页面: <%@pagecontentType="text/html;charset=gb2312"language="java"import="java.sql.*"errorPage=""%> <%request.setCharacterEncoding("gb2312");%> <%@includefile="conn.jsp"%> <%Stringaction=request.getParameter("action");%> <% if(action.equals("gh")){ java.text.SimpleDateFormatformatter=newjava.text.SimpleDateFormat("yyyy-MM-dd"); java.util.DatecurrentTime=newjava.util.Date();//得到当前系统时间 Stringtb_date1=formatter.format(currentTime).toString();;//将日期时间格式化 Stringid=request.getParameter("id"); Statementstmt=conn.createStatement(); intrtn=stmt.executeUpdate("updatetb_jie_huanset jh_j_time='"+tb_date1+"'wherejh_book_ID='"+id+"'"); conn.close(); stmt.close(); } %> alert("还书成功! "); window.location.href="bookBack.jsp";//调回还书表 四、借书信息管理: <%@includefile="conn.jsp"%> <% Stringid=request.getParameter("id"); Stringbook_id=request.getParameter("book_id"); Statementstmt=conn.createStatement(); ResultSetrs=stmt.executeQuery("select*fromtb_jiewhereuser_I='"+id+"'andbook_ID='"+book_id+"'"); while(rs.next()){ %> 姓名: ------ 图书名称: 5px;"> <%=rs.getString("book_name")%> <%}conn.close();%> 借书成功: <%@pagecontentType="text/html;charset=gb2312"language="java"import="java.sql.*"errorPage=""%> <%request.setCharacterEncoding("gb2312");%> <%@includefile="conn.jsp"%> <%Stringaction=request.getParameter("action");%> <% if(action.equals("jy")){ Stringid=request.getParameter("id"); Stringbook_id=request.getParameter("book_id"); Stringadmin_id=request.getParameter("admin_id"); Statementstmt=conn.createStatement(); intrtn=stmt.executeUpdate("insertintotb_jie_huan(jh_book_ID,jh_user_ID,jh_admin_ID)values('"+book_id+"','"+id+"','"+admin_id+"')"); conn.close(); stmt.close(); } %> alert("借书成功! "); window.location.href="bookBorrow.jsp"; 自动跳转: alert("图书信息添加成功! "); window.location.href="book.jsp"; 连入外部连接: 关闭当前窗口: functionmyclose(){ if(confirm("真的要关闭当前窗口吗? ")){ window.close();//关闭俄窗口 window.loacation.href="定向的页面" } } 五、用户管理: functioncheck(form){ if(form.name.value==""){ alert("请输入管理员名称! ");form.name.focus();returnfalse; } if(form.pwd.value==""){ alert("请输入密码! ");form.pwd.focus();returnfalse; } } 管理员名称: 管理员密码: 借阅到期提醒: if(coll==null||coll.isEmpty()){ }else{ //通过迭代方式显示数据 Iteratorit=coll.iterator(); Stringbookname=""; Stringbookbarcode=""; Stringreaderbar=""; Stringreadername=""; StringborrowTime=""; StringbackTime=""; while(it.hasNext()){ BorrowFormborrowForm=(BorrowForm)it.next(); bookname=chStr.toChinese(borrowForm.getBookName()); bookbarcode=borrowForm.getBookBarcode(); readerbar=chStr.toChinese(borrowForm.getReaderBarcode()); readername=chStr.toChinese(borrowForm.getReaderName()); borrowTime=borrowForm.getBorrowTime(); backTime=borrowForm.getBackTime(); }} 1.验证登陆: <%@includefile="conn.jsp"%> <% StringUserName=request.getParameter("admin"); StringUserPwd=request.getParameter("pwd"); Statementstmt_Check=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); Stringsql="select*fromLH_adminwhereadmin_ID='"+UserName+"'andadmin_pwd='"+UserPwd+"'"; ResultSetRsLoginCheck=stmt_Check.executeQuery(sql); if(RsLoginCheck.next()) { session.setAttribute("UserName",UserName); response.sendRedirect("main.jsp"); } else { out.print("用户或密码错误! ! ! ! 请重新登陆"); } RsLoginCheck.close(); stmt_Check.close(); conn.close(); %> 错误: <% Stringerror=(String)request.getAttribute("error"); %> 错误提示信息: <%=error%> 2.管理员的添加: 判断管理员密码: functioncheck(form){ if(form.pwd.value==""){ alert("请输入管理员密码! ");form.pwd.focus();return; } if(form.pwd1.value=="")
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 代码