java课程设计--电话号码查询系统

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

山东建筑大学Java课程设计报告设计题目电话号码查询系统学生姓名黄瑜学号专业班级信计101指导教师王文1、设计目的1、通过JAVA课程设计,使大家能够将学到的面向对象的设计思想运用在具体工作和学习中,加深对类和对象的理解,要求学生对生活中许多具体的事物抽象出类。2、通过这次课程设计掌握JAVA的编程思想,为后续设计编程打下基础。3、培养实际操作能力和实践能力,为以后的工作打下坚实的基础。2、总体设计3、详细设计homework\src\com\work为工作空间bean文件夹下的TelBean.java为Bean类operate文件夹下的TelOperate.java为服务器接收信息端,可以对所获取的信息进行相应的方法调用。TelSql.java对数据库中的数据进行增删改查。sql文件夹下Conn.java为对数据库提供驱动加载等操作。addInfo.jsp为添加信息页面(截图中有相应的运行图)index.jsp为首页页面信息listInfo.jsp为查询之后显示信息的页面searchInfo.jsp为查询条件选择页面电话号码查询系统相应操作添加号码向数据库中添加号码信息删除号码删除相应号码信息修改号码修改相应号码信息查询号码按姓名查询号码按电话号码查询按部门查询号码4、调试与测试调试中部分功能的测试结果及截图:1、电话管理功能列表2、添加电话号码:添加成功3、显示所有电话号码信息4、按姓名查询功能及查询结果查询结果5、按电话号码查询功能及查询结果查询结果6、按部门查询5、源程序清单和执行结果ifexists(select*fromdbo.sysobjectswhereid=object_id(N'[dbo].[search]')andOBJECTPROPERTY(id,N'IsUserTable')=1)droptable[dbo].[search]GOCREATETABLE[dbo].[search]([name][nvarchar](20)COLLATEChinese_PRC_CI_ASNOTNULL,[tel][varchar](11)COLLATEChinese_PRC_CI_ASNULL,[dep][nvarchar](20)COLLATEChinese_PRC_CI_ASNULL)ON[PRIMARY]GOBeanpublicclassTelBean{privateStringname;privateStringtel;privateStringdep;publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicStringgetTel(){returntel;}publicvoidsetTel(Stringtel){this.tel=tel;}publicStringgetDep(){returndep;}publicvoidsetDep(Stringdep){this.dep=dep;}}OperateTeloperatepublicclassTelOperateextendsHttpServlet{/***ThedoGetmethodoftheservlet.br**Thismethodiscalledwhenaformhasitstagvaluemethodequalstoget.**@paramrequesttherequestsendbytheclienttotheserver*@paramresponsetheresponsesendbytheservertotheclient*@throwsServletExceptionifanerroroccurred*@throwsIOExceptionifanerroroccurred*/publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{request.setCharacterEncoding(utf-8);response.setCharacterEncoding(utf-8);//初始化PrintWriterpw=response.getWriter();Stringtype=request.getParameter(type);Stringname=request.getParameter(username);Stringtel=request.getParameter(tel);Stringdep=request.getParameter(dep);TelSqltelSql=newTelSql();//根据出入type判断操作方式if(type.equals(search)){//根据条件查询ArrayListTelBeansearchList=telSql.geTelListByInfo(name,tel,dep);request.getSession().setAttribute(listResult,searchList);request.getRequestDispatcher(listInfo.jsp).forward(request,response);}elseif(type.equals(add)){//添加if(telSql.addTelInfo(name,tel,dep))pw.print(true);elsepw.print(false);}elseif(type.equals(list)){//列表ArrayListTelBeandisplayList=telSql.geTelList();request.getSession().setAttribute(listResult,displayList);request.getRequestDispatcher(listInfo.jsp).forward(request,response);}elseif(type.equals(del)){//删除指定信息telSql.delTelInfo(name);ArrayListTelBeandisplayList=telSql.geTelList();request.getSession().setAttribute(listResult,displayList);request.getRequestDispatcher(listInfo.jsp).forward(request,response);}}/***ThedoPostmethodoftheservlet.br**Thismethodiscalledwhenaformhasitstagvaluemethodequalstopost.**@paramrequesttherequestsendbytheclienttotheserver*@paramresponsetheresponsesendbytheservertotheclient*@throwsServletExceptionifanerroroccurred*@throwsIOExceptionifanerroroccurred*/publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{this.doGet(request,response);}}Telsqlimportjava.sql.*;importjava.util.*;publicclassTelSql{privateConnectionct=null;privatePreparedStatementps=null;privateResultSetrs=null;publicArrayListTelBeangeTelList(){ArrayListTelBeanal=newArrayListTelBean();TelBeantelBean=null;try{ct=newConn().getConn();ps=ct.prepareStatement(select*fromsearch);rs=ps.executeQuery();while(rs.next()){telBean=newTelBean();telBean.setName(rs.getString(name));telBean.setTel(rs.getString(tel));telBean.setDep(rs.getString(dep));al.add(telBean);}}catch(Exceptione){e.printStackTrace();returnal;//TODO:handleexception}finally{this.close();}returnal;}publicArrayListTelBeangeTelListByInfo(Stringname,Stringtel,Stringdep){ArrayListTelBeanal=newArrayListTelBean();TelBeantelBean=newTelBean();if(dep.equals(tech)){dep=技术部;}elseif(dep.equals(sale)){dep=销售部;}elseif(dep.equals(admin)){dep=行政部;}try{ct=newConn().getConn();Stringsql=select*fromsearchwhere;if((!name.equals())&&(!tel.equals())&&(!dep.equals(no))){sql=sql+name='+name+'andtel='+tel+'anddep='+dep+';}elseif((!name.equals())&&(!tel.equals())){sql=sql+name='+name+'andtel='+tel+';}elseif((!name.equals())&&(!dep.equals(no))){sql=sql+name='+name+'anddep='+dep+';}elseif((!tel.equals())&&(!dep.equals(no))){sql=sql+tel='+tel+'anddep='+dep+';}elseif(!name.equals()){sql=sql+name='+name+';}elseif(!tel.equals()){sql=sql+tel='+tel+';}elseif(!dep.equals(no)){sql=sql+dep='+dep+';}ps=ct.prepareStatement(sql);rs=ps.executeQuery();while(rs.next()){telBean.setName(rs.getString(name));telBean.setTel(rs.getString(tel));telBean.setDep(rs.getString(dep));al.add(telBean);}}catch(Exceptione){e.printStackTrace();returnal;//TODO:handleexception}finally{this.close();}returnal;}publicbooleanaddTelInfo(Stringname,Stringtel,Stringdep){booleanflag=false;try{ct=newConn().getConn();ps=ct.prepareStatemen

1 / 10
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功