您好,欢迎访问三七文档
《网上书店信息管理系统的设计与实现》第1页共34页附录全部源代码packagecom.shoeShop.db;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.SQLException;publicclassConnect{privatestaticConnectioncon=null;privatestaticStringurl=jdbc:oracle:thin:@localhost:1521:ORCL;privatestaticStringdriver=oracle.jdbc.driver.OracleDriver;privatestaticStringuser=scott;privatestaticStringpwd=tiger;publicstaticConnectiongetConnection(){try{Class.forName(driver);con=DriverManager.getConnection(url,user,pwd);System.out.println(数据库连接成功!);}catch(ClassNotFoundExceptione){System.out.println(驱动加载失败!);;}catch(SQLExceptione){System.out.println(数据库连接失败!);}returncon;}publicstaticvoidmain(String[]args){Connect.getConnection();}}《网上书店信息管理系统的设计与实现》第2页共34页packagecom.shoeShop.action;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjavax.swing.JPanel;importcom.shoeShop.view.RegisterFrame;publicclassdocMenuActionimplementsActionListener{RegisterFrameregister=null;JPanelcusPanel=null;JPaneldocPanel=null;publicdocMenuAction(RegisterFrameregister){this.register=register;this.cusPanel=register.cusPanel;this.docPanel=register.docPanel;}publicvoidactionPerformed(ActionEvente){//TODOAuto-generatedmethodstubregister.flag=1;//System.out.println(register.flag);register.remove(cusPanel);register.add(docPanel);docPanel.updateUI();}}packagecom.shoeShop.dao;《网上书店信息管理系统的设计与实现》第3页共34页importjava.sql.Connection;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;importcom.shoeShop.db.Connect;importcom.shoeShop.entity.Buyer;importcom.shoeShop.entity.Seller;publicclassBuyerDao{privatestaticConnectionconn;privatestaticStatementstatement;privatestaticResultSetresultSet;//插入数据,用于注册publicintinsertBuyer(Buyerbuyer){intflag=0;conn=Connect.getConnection();try{statement=conn.createStatement();Stringsql=insertintobuyervalues('+buyer.getId()+','+buyer.getName()+','+buyer.getPwd()+','+buyer.getAddress()+');//System.out.println(buyer+sql);flag=statement.executeUpdate(sql);statement.close();conn.close();}catch(SQLExceptione){//TODOAuto-generatedcatchblock《网上书店信息管理系统的设计与实现》第4页共34页e.printStackTrace();}//System.out.println(flag);returnflag;}//通过用户名和密码查询,用于登录publicstaticBuyergetBuyer(Stringname,Stringpwd){conn=Connect.getConnection();Buyerbuyer=newBuyer();try{statement=conn.createStatement();Stringsql=select*frombuyerwherebuyer_id='+name+'andpwd='+pwd+';resultSet=statement.executeQuery(sql);while(resultSet.next()){buyer.setId(resultSet.getString(buyer_id));buyer.setName(resultSet.getString(buyer_name));buyer.setPwd(resultSet.getString(pwd));buyer.setAddress(resultSet.getString(address));}resultSet.close();statement.close();conn.close();}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}returnbuyer;}《网上书店信息管理系统的设计与实现》第5页共34页publicstaticvoidmain(String[]args){BuyerDaodao=newBuyerDao();System.out.println(dao.getBuyer(zxk,654321));//Buyerbuyer=newBuyer();//buyer.setId(lily);//buyer.setName(长理专卖);//buyer.setPwd(123456);//buyer.setAddress(湖南长沙);//dao.insertBuyer(buyer);}}packagecom.shoeShop.dao;importjava.sql.Connection;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;importjava.util.ArrayList;importcom.shoeShop.db.Connect;importcom.shoeShop.entity.Goods;importcom.shoeShop.entity.Seller;importcom.shoeShop.imp.User;publicclassGoodsDao{privatestaticConnectionconn;privatestaticStatementstatement;privatestaticResultSetresultSet;《网上书店信息管理系统的设计与实现》第6页共34页//查询登录商家的所有商品,用于商家管理自己的商品publicArrayListgetAllGoods(){ArrayListlist=newArrayList();conn=Connect.getConnection();try{statement=conn.createStatement();Stringsql=select*fromgoodsa,sellerbwherea.seller_id=b.seller_idandb.seller_id='+User.getUserName()+';resultSet=statement.executeQuery(sql);while(resultSet.next()){Sellerseller=newSeller();seller.setName(resultSet.getString(seller_name));seller.setAddress(resultSet.getString(address));Goodsgoods=newGoods();goods.setSeller(seller);goods.setId(resultSet.getInt(goods_id));goods.setName(resultSet.getString(goods_name));goods.setSeller_id(resultSet.getString(seller_id));goods.setDiscount(resultSet.getInt(discount));goods.setNum(resultSet.getInt(num));goods.setPrice(resultSet.getInt(price));//System.out.println(goods.toString());list.add(goods);}}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}finally{try{《网上书店信息管理系统的设计与实现》第7页共34页resultSet.close();statement.close();conn.close();}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}returnlist;}//查询所有商家的所有商品.用于用户搜索商品publicArrayListgetAllSellerGoods(){ArrayListlist=newArrayList();conn=Connect.getConnection();try{statement=conn.createStatement();Stringsql=select*fromgoodsa,sellerbwherea.seller_id=b.seller_id;resultSet=statement.executeQuery(sql);while(resultSet.next()){Sellerseller=newSeller();seller.setName(resultSet.getString(seller_name));seller.setAddress(resultSet.getString(address));Goodsgoods=newGoods();goods.setSeller(seller);goods.setId(resultSet.getInt(goods_id));goods.setName(resultSet.getString(goods_name));goods.se
本文标题:网上书店完整代码
链接地址:https://www.777doc.com/doc-5565068 .html