本程序主要完成上述的功能创建了3个表货物表:Goods会员表:Member货物订购:Order代码:packageentity;publicclassGoods{privateStringnumber;privateStringname;privatedoubleprice;privateStringunit;//单位privateintamount;publicGoods(){super();}publicGoods(Stringnumber,Stringname,doubleprice,Stringunit,intamount){super();this.number=number;this.name=name;this.price=price;this.unit=unit;this.amount=amount;}publicStringgetNumber(){returnnumber;}publicvoidsetNumber(Stringnumber){this.number=number;}publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicdoublegetPrice(){returnprice;}publicvoidsetPrice(doubleprice){this.price=price;}publicStringgetUnit(){returnunit;}publicvoidsetUnit(Stringunit){this.unit=unit;}publicintgetAmount(){returnamount;}publicvoidsetAmount(intamount){this.amount=amount;}}packageentity;publicclassMember{privateintmemberNumber;privateStringtime;publicMember(){super();}publicMember(intmemberNumber,Stringtime){super();this.memberNumber=memberNumber;this.time=time;}publicStringgetTime(){returntime;}publicvoidsetTime(Stringtime){this.time=time;}publicintgetMemberNumber(){returnmemberNumber;}publicvoidsetMemberNumber(intmemberNumber){this.memberNumber=memberNumber;}}packageentity;publicclassOrder{privateStringgoodsNumber;privateStringgoodsName;privatedoubleprice;privateintamount;privatedoublemoney;privateStringtime;publicOrder(){super();}publicOrder(StringgoodsNumber,StringgoodsName,doubleprice,intamount,doublemoney,Stringtime){super();this.goodsNumber=goodsNumber;this.goodsName=goodsName;this.price=price;this.amount=amount;this.money=money;this.time=time;}publicOrder(StringgoodsNumber,StringgoodsName,doubleprice,intamount,doublemoney){super();this.goodsNumber=goodsNumber;this.goodsName=goodsName;this.price=price;this.amount=amount;this.money=money;}publicStringgetGoodsNumber(){returngoodsNumber;}publicvoidsetGoodsNumber(StringgoodsNumber){this.goodsNumber=goodsNumber;}publicStringgetGoodsName(){returngoodsName;}publicvoidsetGoodsName(StringgoodsName){this.goodsName=goodsName;}publicdoublegetPrice(){returnprice;}publicvoidsetPrice(doubleprice){this.price=price;}publicintgetAmount(){returnamount;}publicvoidsetAmount(intamount){this.amount=amount;}publicdoublegetMoney(){returnmoney;}publicvoidsetMoney(doublemoney){this.money=money;}publicStringgetTime(){returntime;}publicvoidsetTime(Stringtime){this.time=time;}}packagedao;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.sql.SQLException;publicclassBaseDao{privatestaticStringdriverName=com.mysql.jdbc.Driver;privatestaticStringurl=jdbc:mysql://localhost:3306/textDE;privatestaticStringuid=root;privatestaticStringpwd=root;//连接数据库的方法publicstaticConnectiongetConnection(){Connectionconn=null;try{Class.forName(driverName);conn=DriverManager.getConnection(url,uid,pwd);}catch(Exceptione){e.printStackTrace();}returnconn;}//释放资源的方法publicstaticvoidcloseAll(Connectionconn,PreparedStatementps,ResultSetrs){try{if(rs!=null)rs.close();if(ps!=null)ps.close();if(conn!=null)conn.close();}catch(SQLExceptione){e.printStackTrace();}}}packagedao;importjava.sql.Connection;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.util.ArrayList;importentity.Goods;importentity.Member;importentity.Order;publicclassBaseMarketDao{Connectionconn=null;PreparedStatementps=null;ResultSetrs=null;//新增商品publicintaddGoods(Goodsg){intnum=0;try{conn=BaseDao.getConnection();Stringsql=insertintogoodsvalues(?,?,?,?,?);ps=conn.prepareStatement(sql);ps.setString(1,g.getNumber());ps.setString(2,g.getName());ps.setDouble(3,g.getPrice());ps.setString(4,g.getUnit());ps.setInt(5,g.getAmount());num=ps.executeUpdate();}catch(Exceptione){//TODO:handleexception}finally{BaseDao.closeAll(conn,ps,rs);}returnnum;}//更改商品的数量(0增加1减少)publicintchangeAmount(Stringnumber,intamount,inttype){intnum=0;try{conn=BaseDao.getConnection();Stringsql;if(type==0)sql=updategoodssetamount=amount+?wherenumber=?;elsesql=updategoodssetamount=amount-?wherenumber=?;ps=conn.prepareStatement(sql);ps.setInt(1,amount);ps.setString(2,number);num=ps.executeUpdate();}catch(Exceptione){//TODO:handleexception}finally{BaseDao.closeAll(conn,ps,rs);}returnnum;}//列举所有的商品publicArrayListGoodsallGoods(){ArrayListGoodsal=newArrayListGoods();Goodsg=null;try{conn=BaseDao.getConnection();Stringsql=select*fromgoods;ps=conn.prepareStatement(sql);rs=ps.executeQuery();while(rs.next()){g=newGoods();g.setNumber(rs.getString(number));g.setName(rs.getString(name));g.setPrice(rs.getDouble(price));g.setUnit(rs.getString(unit));g.setAmount(rs.getInt(amount));al.add(g);}}catch(Exceptione){//TODO:handleexception}finally{BaseDao.closeAll(conn,ps,rs);}returnal;}//根据编号查找想要的商品publicGoodssearchGoods(Stringnumber){Goodsg=null;try{conn=BaseDao.getConnection();Stringsql=select*fromgoodswherenumber=?;ps=conn.prepareStatement(sql);ps.setString(1,number);rs=ps.executeQuery();while(rs.next()){g=newGoods();g.setNumber(rs.getString(number));g.setName(rs.getString(name));g.setPrice(rs.getDouble(pri