资源描述:
《《javaweb期中》word版》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、Web期中作业——超市管理系统姓名:刘先亮学号:21114160106班级:信1131一、期中题目根据JavaWeb课上的实例,运用所学的Web开发技术设计完成一个超市管理系统。二、功能要求实现超市货物的增删改查展示功能,实现简易的构建和界面设计。基于xampp中的MySQL数据库,以MyEclipse软件为开发工具。1.数据库的建立(1).代码如下:CREATETABLEMerchInfo(MerchIDint,MerchNamevarchar(50),importPriceint,warehousepriceint,categoriesvar
2、char(50),MerchNumint,porfferNamevarchar(50),primarykey(MerchID),);(2).数据的插入insertintoMerchInfo(MerchID,MerchName,importPrice,warehouseprice,categories,MerchNum,porfferName)values("112031","牛奶","3","3.5","饮料","120","蒙牛");insertintoMerchInfo(MerchID,MerchName,importPrice,warehousep
3、rice,categories,MerchNum,porfferName)values("112032","酸酸乳","2.5","3.5","饮料","110","伊利");insertintoMerchInfo(MerchID,MerchName,importPrice,warehouseprice,categories,MerchNum,porfferName)values("112052","方便面","2","4","生活类","123","康师傅");insertintoMerchInfo(MerchID,MerchName,importPr
4、ice,warehouseprice,categories,MerchNum,porfferName)values("112055","面包","7","12","甜品","123","盼盼");效果图:2.搭建数据库连接环境,在工作项目下的src文件夹中,创建包名为cn.edu.jiu.db的包,在包内新建DBUtil.Java文件代码如下:packagecn.edu.jiu.db;importjava.sql.*;importjava.util.*;publicclassDBUtil{privateConnectionconn;privateStat
5、ementstmt;privateResultSetrs;publicbooleangetConnection(){booleanret=false;try{Class.forName("com.mysql.jdbc.Driver");Stringurl="jdbc:mysql://127.0.0.1:3306/supermarket?"+"&useUnicode=true&characterEncoding=gb2312";Stringuser="root";Stringpassword="";conn=DriverManager.getConnect
6、ion(url,user,password);}catch(Exceptione){e.printStackTrace();}returnret;}publicintexecuteUpdate(Stringsql){intret=0;try{getConnection();stmt=conn.createStatement();ret=stmt.executeUpdate(sql);close();}catch(Exceptione){e.printStackTrace();}returnret;}publicResultSetexecuteQuery(
7、Stringsql){try{getConnection();stmt=conn.createStatement();rs=stmt.executeQuery(sql);}catch(Exceptione){e.printStackTrace();}returnrs;}publicvoidclose(){try{if(rs!=null)rs.close();if(stmt!=null)stmt.close();if(conn!=null&&!conn.isClosed())conn.close();}catch(Exceptione){e.printSt
8、ackTrace();}}publicstaticvoidmain(String